csrf token not working

350 views
Skip to first unread message

Bobby Roberts

unread,
Jul 2, 2011, 12:15:29 PM7/2/11
to Django users
I'm looking at the docs at https://docs.djangoproject.com/en/dev/ref/contrib/csrf/
for CSRF implementation. I've got steps 1 and 2 done but the csrf
token is not even showing in the form even though i have {%csrf_token
%} within the form html.... any ideas what would cause it not to
create a token?

Hervé Edorh

unread,
Jul 3, 2011, 10:52:23 AM7/3/11
to Django users
hi,
step 3, put "django.core.context_processors.csrf" in your
TEMPLATE_CONTEXT_PROCESSORS and if you use django 1.3 use "render()"
in place of render_to_response in yours views. Or if you want to use
render_to_response put "context_instance=RequestContext(request)" at
the end of render_to_response

On Jul 2, 4:15 pm, Bobby Roberts <tchend...@gmail.com> wrote:
> I'm looking at the docs athttps://docs.djangoproject.com/en/dev/ref/contrib/csrf/

Vusal Alishov

unread,
Jul 3, 2011, 12:29:51 PM7/3/11
to django...@googlegroups.com
example :
in views:
def foo(request):
    c = {"foo": "bar"}
    c.update(csrf(request))
    return render('test.html',c)

2011/7/3 Hervé Edorh <seno...@gmail.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.


Hervé Edorh

unread,
Jul 3, 2011, 6:16:33 PM7/3/11
to Django users
With django.core.context_processor.csrf that i explain, you don't need
to do anything in yours views like below.
Reply all
Reply to author
Forward
0 new messages