django1.21加入了防止CSRF攻击的模块。

这是django的debug模式下给出的错误提示页面。

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:

  • 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.

    在用户用POST方法提交页面信息的时候,有时会遇到这样的错误。在网上找了一些解决方案,其中比较方便的一个是在settings.py里面的MIDDLEWARE_CLASSES 中加入'django.middleware.csrf.CsrfResponseMiddleware', 错误就消除了。

CSRF verification failed. Request aborted.的解决办法相关推荐

  1. Django 3.1.5, CSRF verification failed. Request aborted.

    post请求django的时候出现:CSRF verification failed. Request aborted 问题翻译: 一般而言,这可以发生时,有一个真正的跨站请求伪造,或当Django的 ...

  2. Django web : CSRF verification failed. Request aborted.

    错误标题:CSRF verification failed. Request aborted. 错误描述: HelpReason given for failure:CSRF cookie not s ...

  3. Python Django提交表单时报错:Forbidden (403) CSRF verification failed. Request aborted.

    报错截图: 解决方法: 把settings里面一个叫csrf的安全机制的注释掉即可. MIDDLEWARE = ['django.middleware.security.SecurityMiddlew ...

  4. CSRF verification failed. Request aborted.

    当运行一个django项目后,出现了这样的一个错误,如图: 这时我们只要在settings.py中注释掉一行即可. 'django.middleware.csrf.CsrfViewMiddleware ...

  5. CSRF verification failed. Request aborted. 表单提交方法为POST时的报错

    本人所用Django版本为1.11,在设置请求方法为POST时,遇到标题中的错误,尝试了多种方法,最终通过下面的操作来修复: 在template文件中添加图中红框部分 接着,导入csrf_exempt ...

  6. Django错误解决: CSRF verification failed. Request abor

    2019独角兽企业重金招聘Python工程师标准>>> 该解决办法是根据个技术博文上修改后的,因以为原方法无法解决这个错误,以下内容是根据我实际操作过程修正的. Forbidden  ...

  7. Django POST CSRF verification failed. Request abor

    问题 在使用Django搭建好测试环境后,写了一个提交POST表单提交留言的测试页面. 如图: 填写表单,点击"提交留言"按钮提交到服务器,却出现 Forbidden (403) ...

  8. curl: (25) Failed FTP upload: 550 解决办法

    问题描述 今天使用 curl 调用ftp上传文件抛出一下错误 sam@sam-hp-z238:~$ curl -T /home/sam/myinstall ftp://192.168.2.48/cam ...

  9. SSH连接时出现Host key verification failed的原因及解决方法

    SSH连接时出现Host key verification failed的原因及解决方法 参考文章: (1)SSH连接时出现Host key verification failed的原因及解决方法 ( ...

最新文章

  1. java登录注册原理_案例:登录注册实现
  2. 翻译连载 | JavaScript轻量级函数式编程-第7章: 闭包vs对象 |《你不知道的JS》姊妹篇...
  3. issubclass和isinstance 反射 内置方法(魔术方法)
  4. 31.return和call的区别
  5. linux 命令调试分析core文件,linux环境下dump vmcore文件分析
  6. 雅虎正开发聊天机器人挑战对手 不过似乎很难成功
  7. 文本框只能输入数字代码
  8. AT2675 [AGC018F] Two Trees(欧拉回路)
  9. rabbitmq-通配符模式
  10. NY : 括号匹配问题
  11. html中显示日历的代码,用css+html+javascript实现简单日历的代码
  12. python程序设计课程标准_《Python程序设计》课程标准
  13. Android +kotlin Banner 轮播广告 获取后台数据
  14. pythonQQ机器人系列(基于go-cqhttp):使用requests和socket实现QQ机器人聊天(2-0)
  15. Python 实现按键精灵的功能,超简单详细(Windows版)
  16. 如何用ps做故障艺术风格效果
  17. 统一身份认证实现,推广的可能性及优缺点?
  18. ChatGPT  一本正经的胡说八道 那也看看原理吧
  19. 程序员投简历到底是“精投”好,还是“广撒网”好?
  20. maven:only whitespace content allowed before start tag and not \u0 (position: START_DOCUMENT

热门文章

  1. html之div拖拽,html5拖拽
  2. matlab和本机MySQL链接
  3. OCS2007标准版服务器部署
  4. 用迭代法求方程cos(y)-y=0的一个实根
  5. PTA:图的理论习题集
  6. 数据安全治理所遵循的有哪些原则
  7. 数据挖掘有哪些主要步骤
  8. 使用递归函数求解字符串的逆置问题
  9. python中loadpage_实现加载页Loading Page 的几种方法
  10. python股票数据分析_Python股票分析(一)获取历史数据