Question

I put a login box alone with a keyword search box in 404.html in a Django project so in case a 404 error is raised, visitors get more options to jump to other parts.

But the CSRF middleware doesn't work in 404 error page with no csrf token rendered. I tried move 'django.middleware.csrf.CsrfViewMiddleware' to first of MIDDLEWARE_CLASSES in settings.py but did not work either.

Anyone knows a solution?

Was it helpful?

Solution

My idea is you should make your own error handler and generate the token manually with django.middleware.csrf.get_token()

OTHER TIPS

Looks like they've fixed this in Django http://code.djangoproject.com/ticket/14565

That said, it doesn't seem to be in the latest release, so I created a custom error view with the same contents as 'django.views.defaults.page_not_found', making the changes found in the ticket diff file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top