[Answer]-Django Book OUTDATE CSRF protection

1👍

Djangobook uses a pretty old version of django, you may be on a newer version, I have tried the information and csrf section is definitely outdated since they had some modification to the way this is handled in newer versions, match your django version with the book version, also some frequent reasons for this error (In addition to the middleware thing mentioned by pahko) are

  1. not using csrf_token tag in template
  2. not using RequestContext class – replace Context with RequestContext

like this

from django.template import RequestContext

and in the render statement

return render_to_response("home/index.html", c, context_instance=RequestContext(request))

note: use your own template path in above statement.

0👍

try to put this in your middleware config in settings.py

MIDDLEWARE_CLASSES = (
    'django.middleware.csrf.CsrfViewMiddleware',
)

hope it helps

👤pahko

Leave a comment