Discussion:
CSRF verification failed. Request aborted.
Harbhag Singh Sohal
2010-12-22 13:35:02 UTC
Permalink
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.middleware.csrf.CsrfResponseMiddleware',
)

Above is my settings.py file, even then I am getting the CSRF
verification failure error.
--
Harbhag Singh Sohal
http://harbhag.wordpress.com
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com.
To unsubscribe from this group, send email to django-users+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Harbhag Singh Sohal
2010-12-22 13:41:40 UTC
Permalink
I am also using {% csrf_token %}, even then I am getting error.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com.
To unsubscribe from this group, send email to django-users+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
robos85
2010-12-22 13:53:20 UTC
Permalink
Do You pass *RequestContext* to your template during rendering it in view?
Example from manual:

def my_view(request):
c = {}
# ...
return render_to_response("a_template.html", c,
context_instance=RequestContext(request))
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com.
To unsubscribe from this group, send email to django-users+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Harbhag Singh Sohal
2010-12-22 13:55:39 UTC
Permalink
from django.template import RequestContext
return render_to_response('abook_view.html',
locals(),context_instance=RequestContext(request))

this is what I am using. Is it ok ?
--
Harbhag Singh Sohal
http://harbhag.wordpress.com
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com.
To unsubscribe from this group, send email to django-users+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Dan Fairs
2010-12-22 14:20:50 UTC
Permalink
Post by Harbhag Singh Sohal
from django.template import RequestContext
return render_to_response('abook_view.html',
locals(),context_instance=RequestContext(request))
What you're doing should be fine, in terms of whether it works or not. However, I'd strongly recommend against passing locals(). While it may seem to violate DRY to do anything else, experience has shown me that it makes maintaining the code a lot harder in the long run, as it's not immediately obvious exactly what is being passed to the template. It's obvious what's being passed from the tiny view you've got there, but as your views grow, this will become a problem.

Cheers,
Dan

--
Dan Fairs | ***@gmail.com | www.fezconsulting.com
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com.
To unsubscribe from this group, send email to django-users+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Harbhag Singh Sohal
2010-12-22 15:01:05 UTC
Permalink
Post by Dan Fairs
What you're doing should be fine, in terms of whether it works or not. However, I'd strongly recommend against passing locals(). While it may seem to violate DRY to do anything else, experience has shown me that it makes maintaining the code a lot harder in the long run, as it's not immediately obvious exactly what is being passed to the template. It's obvious what's being passed from the tiny view you've got there, but as your views grow, this will become a problem.
The error is solved now, and I will keep your advice about locals() in
my mind. Thanks
--
Harbhag Singh Sohal
http://harbhag.wordpress.com
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com.
To unsubscribe from this group, send email to django-users+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Continue reading on narkive:
Loading...