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
随机推荐
- angular的$scope,这东西满重要的
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- 50行代码仿backbone_todos
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- __HTML_5读取文件API
//HTML5 __FileSystemApi <!doctype html> <html> <head> <meta charset="utf-8 ...
- Java-编写一个jdbc操作类
1.通过读取文件配置 package 数据库操作类; /* * Db.java Created on 2007年8月20日, 上午 8:37 */ import java.io.*; import j ...
- Hive 正则匹配函数 regexp_extract
regexp_extract 语法: regexp_extract(string subject, string pattern, int index) 返回值: string 说明: 将 ...
- No message found under code ' for locale 'en'.
1.如果你使用eclipse创建的工程是class和src分开的,那么资源属性文件一定要放在src目录以内.2.属性文件名的写法:messages_zh_CN.properties (中文)messa ...
- SQL增加、删除、更改表中的字段名
1. 向表中添加新的字段 ) not null 2. 删除表中的一个字段 delete table table_name column column_name 3. 修改表中的一个字段名 alter ...
- bootstrap学习总结-06 按钮
一按钮的基本样式 Bootstrap提供一组标准的按钮配色和大小调整方案,只需要简单的应用的按钮类即可.BootStrap3提供了按钮的标准样式如图. <!DOCTYPE html> &l ...
- iOS推送失败的可能问题汇总
ITC上的证书问题 AppID未开启推送 Provioning Profile在AppID开启推送功能前生成的 Provioning证书过期 推送的pem证书过期 客户端问题 target的CodeS ...
- POJ1679The Unique MST(次小生成树)
The Unique MST Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 25203 Accepted: 8995 D ...