views:

170

answers:

1

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?

A: 

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

zalew