100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > Django在form提交CSRF验证失败. 相应中断问题

Django在form提交CSRF验证失败. 相应中断问题

时间:2021-11-20 04:04:40

相关推荐

Django在form提交CSRF验证失败. 相应中断问题

CSRF验证失败. 相应中断.

1).首先,我们可以先看一下出现问题的所在的原因。

Your browser is accepting cookies.The view function passes arequestto the template'srendermethod.In the template, there is a{% csrf_token %}template tag inside each POST form that targets an internal URL.If you are not usingCsrfViewMiddleware, then you must usecsrf_protecton any views that use thecsrf_tokentemplate tag, as well as those that accept the POST data. 2),不难发现,我们是在上面的问题中有一个{% csrf_token %},这是一个网络漏洞,在所有的表单的提交中,都需要添加,而且,必须放在format 后面。 接着,我们应该查找一下seting 中的MIDDLEWARE_CLASSES 是否缺少了django.middleware.csrf.CsrfViewMiddleware这也可能是造成出错的原因。3).在app 中的views 中可以添加一个fromdjango.templateimportRequestContext,然后,渲染函数render添加即可。例如:returnrender(req,'df_user/login.html',context_instance=RequestContext(req))。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。