Search code examples
pythondjangosecuritycsrfdjango-csrf

Django: name 'csrf_token' is not defined


I've a little problem with adding a csrf_token on my form in Django (1.2.5), though I've added all the necessary middleware classes

{% csrf_token %}

gives the ...name 'csrf_token' is not defined error.

What is the problem?

Sultan


Solution

  • You need to check out your MIDDLEWARE_CLASSES and ensure that the CSRF middleware is in there. As of Django 1.2, this was django.middleware.csrf.CsrfViewMiddleware — ensure that you're using the right class by reading the Django documentation on middleware.