django程序报错CSRF verification failed. Request aborted.
django程序的html页面中form的method='post'的时候报错
Forbidden (403) CSRF verification failed. Request aborted.Help Reason given for failure: CSRF token missing or incorrect. In general, this can occur when there is a genuine Cross Site Request Forgery, or when Django's CSRF mechanism has not been used correctly.
For POST forms, you need to ensure: Your browser is accepting cookies. The view function uses RequestContext for the template,
instead of Context. In the template, there is a {% csrf_token %} template tag inside each POST form that targets an internal URL.
If you are not using CsrfViewMiddleware, then you must use csrf_protect on any views that use the csrf_token template tag,
as well as those that accept the POST data. You're seeing the help section of this page because you have DEBUG = True in your Django settings file.
Change that to False, and only the initial error message will be displayed. You can customize this page using the CSRF_FAILURE_VIEW setting.
处理方法可以先屏蔽 修改web2的settings,屏蔽第100行的中间层csrf 97 MIDDLEWARE_CLASSES = (
98 'django.middleware.common.CommonMiddleware',
99 'django.contrib.sessions.middleware.SessionMiddleware',
100 #'django.middleware.csrf.CsrfViewMiddleware',
当然这个方法是不可取的,
先把csrf屏蔽的内容开启 按照上面的提示操作 print req.POST的时候,会看到 [07/Jun/2014 21:15:41] "GET /post_add/ HTTP/1.1" 200 602
<QueryDict:{.........,u'csrfmiddlewaretoken':[u'I5Jwkfkdsjkgjgfgz']}....>
CSRF(Cross-site request forgery跨站请求伪造,也被称为“one click attack”或者session riding,攻击通过在授权用户访问的页面中包含链接或者脚本的方式工作。例如:一个网站用户Bob可能正在浏览聊天论坛,而同时另一个用户Alice也在此论坛中,并且后者刚刚发布了一个具有Bob银行链接的图片消息。设想一下,Alice编写了一个在Bob的银行站点上进行取款的form提交的链接,并将此链接作为图片tag。如果Bob的银行在cookie中保存他的授权信息,并且此cookie没有过期,那么当Bob的浏览器尝试装载图片时将提交这个取款form和他的cookie,这样在没经Bob同意的情况下便授权了这次事务。
风险在于那些通过基于受信任的输入form和对特定行为无需授权的已认证的用户来执行某些行为的web应用。已经通过被保存在用户浏览器中的cookie进行认证的用户将在完全无知的情况下发送HTTP请求到那个信任他的站点,进而进行用户不愿做的行为。
对于初学者来说,解决方案就是提示信息中所提示的添加一个{%csrf_token%},
django程序报错CSRF verification failed. Request aborted.的更多相关文章
- Django 403错误:CSRF verification failed. Request aborted
网上有解决办法,我自己的组合是: 一,FORM加标识 <form action="" method="post"> {% csrf_token %} ...
- Django1.8:403错误:CSRF verification failed. Request aborted.
问题:Django 403错误:CSRF verification failed. Request aborted. 原因:需要加cookie验证 解决方法: 1.在view.py中增加 fr ...
- django csrf使用教程,解决Forbidden (403)CSRF verification failed. Request aborted.
Django版本号:1.11.15 django中post请求报错:Forbidden (403)CSRF verification failed. Request aborted. HelpReas ...
- Django提交POST表单“CSRF verification failed. Request aborted”问题的解决
1.环境 python 3.4 Django 1.7 Visual Studio 2015 PTVS 2.问题 提交表单,出现以下错误: CSRF verification failed. Reque ...
- CSRF verification failed. Request aborted.错误解决办法
在Django项目的页面,提交form表单POST请求时,会出现报错:CSRF verification failed. Request aborted. 需要在form表单中加:{% csrf_to ...
- CSRF verification failed. Request aborted.
在使用Django提交Post表单时遇到如下错误: Forbidden (403) CSRF verification failed. Request aborted. 原因在"帮助&quo ...
- CSRF verification failed. Request aborted. 表单提交方法为POST时的报错
本人所用Django版本为1.11,在设置请求方法为POST时,遇到标题中的错误,尝试了多种方法,最终通过下面的操作来修复: 在template文件中添加图中红框部分 接着,导入csrf_exempt ...
- Django中关于“CSRF verification failed. Request aborted”的问题
遇到该问题的情境 在Django中采用Ajax提交表单,涉及到跨域问题. 解决措施 在html页面中的表单内添加如下代码: {% csrf_token %} 在视图函数所在的py文件中添加如下代码: ...
- django框架中form表单Post方法无法提交 Forbidden (403) CSRF verification failed. Request aborted.
问题如图: 解决方法: 在视图函数中引入并使用装饰器 from django.views.decorators.csrf import csrf_exempt @csrf_exempt
随机推荐
- ModernUI教程:第一个ModernUI应用(采用项目模板)
在我们开始之前,请确保你已经为你的Visual2012或者2013安装了ModernUI for WPF的模板扩展: >>从Visual Studio 库 下载并安装VSIX扩展 > ...
- css大牛的博客
一个不能再牛的个人简历,请用pc观看:http://strml.net/ 用css来画圆http://jingyan.baidu.com/article/c910274be4dd69cd371d2d4 ...
- [AaronYang]C#人爱学不学[2]
1. 记事本写C#,脱离vs 新建记事本,名字为 helloworld.cs using System; namespace Hello{ public class HelloWorldSay{ st ...
- [C#]MemoryStream.Dispose之后,为什么仍可以ToArray()?
目录 概述 MemoryStream分析 总结 概述 事件起因,一哥们在群里面贴出了类似下面这样的一段代码: class Program { static void Main(string[] arg ...
- oracle 简述
1.数据库有很多的管理工具,Sqlplus是最好的管理工具. 2.sql语句是学习中最难的部分,如何编写出高效的sql 语句是我们的目标 3.oracle的日常最终要的工作就是备份,永远是备份,有数据 ...
- C# 抓取网页Html源码 (网络爬虫)
http://www.cnblogs.com/wxxian001/archive/2011/09/07/2169519.html 刚刚完成一个简单的网络爬虫,因为在做的时候在网上像无头苍蝇一样找资料. ...
- Common Pitfalls In Machine Learning Projects
Common Pitfalls In Machine Learning Projects In a recent presentation, Ben Hamner described the comm ...
- hud 2502 月之数
I think: AC : import java.util.Scanner; public class Main { public static void main(String[] args) { ...
- memcache内存分配机制
memcached的内存分配没有用到c语言中自带的malloc函数,因为这个函数分配内存的时候效率很低,对于这种要求快速响应,对效率要求非常高的缓存软件来说非常不合适. memcached用的是自己的 ...
- zencart资源
http://www.zen-cart.cn/ http://www.ezencart.com/