problems with csrf_token

ぃ、小莉子 提交于 2019-12-02 02:54:29

You haven't quite understood step 3 here: you need to use RequestContext to ensure that the context processor is run.

return render_to_response("edit.html", {"page_name" : page_name,
                                        "content" : content},
                           context_instance=RequestContext(request))

With that, you don't need the c.update(csrf(request)) bit.

You don't need to do anything more.

Just place {% csrf_token %} into your form and send it via POST.

All other stuff will be done inside django.middleware.csrf.CsrfViewMiddleware.

You should enable it in your settings.py (if you haven't done this):

MIDDLEWARE_CLASSES += (`django.middleware.csrf.CsrfViewMiddleware`,)
TEMPLATE_CONTEXT_PROCESSORS += (`django.core.context_processors.csrf`,)

Last line is not required if you use RequestContext (not a simple Context) in your templates (Note: render_to_response() uses Context when direct_to_template() uses RequestContext)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!