当我们必须发送{% csrf_token %}
时,django中的csrftoken
-cookie有什么用
在提交的每一份表格中。在
<form method="post" action="actionFile/">
{% csrf_token %}
<button>Submit</button>
</form>
Django处理器总是请求{% csrf_token %}
我们是否必须将{% csrf_token %}
放在每一个表单中,django处理器不能利用csrftoken
-cookie吗
为了防止伪造,可能需要使用{% csrf_token %}
,但是cookie有什么用呢
请澄清
Cross-site request forgery:
使用秘密cookie
^{pr2}$只接受POST请求
Reference link
Django每次请求服务器时都会设置csrftoken cookie,当您将数据从客户端发布到服务器时,此令牌与该令牌匹配,如果不匹配,则抛出错误,这是恶意请求。在
如果可以使用csrf_exempt decorator来禁用特定视图的csrf保护。在
然后在你的视图前面写
@csrf_exempt
CSRF代表:跨站点请求伪造
当涉及到Web应用程序时,这是一种非常常见的攻击。因此,不仅Django,而且包括rubyonrails在内的大多数其他框架都提供了防止这种攻击的支持。在
在Django中,通过发送“csrfmiddlewaretoken”作为POST数据来完成。然后Django将此令牌的值与合法令牌的值进行匹配。如果它与通过的请求匹配,则会引发错误。在
{%csrf_token%}模板标记生成具有合法csrf令牌值的隐藏输入字段。在
所有处理和异常引发都在CsrfViewMiddleware中完成。 你可以在Django文档中找到更多关于这个的信息(很好的解释):https://docs.djangoproject.com/en/1.6/ref/contrib/csrf/
相关问题 更多 >
编程相关推荐