开发者

Make CSRF middleware work in Django's 404 error pages

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?


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜