django cloudflare csrf 403

网站套了cloudflare flare发现登录接口403了,csrf验证失败,

debug设置为False

详细报错如下:

Reason given for failure:

复制代码
    Referer checking failed - https://xxx/login does not match any trusted origins.
    

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 passes a request to the template's render method.

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

  • The form has a valid CSRF token. After logging in in another browser tab or hitting the back button after a login, you may need to reload the page with the form, because the token is rotated after a login.

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.

实际是跨域问题,具体为什么cloudflare会造成跨域不知道,解决方法:

Django配置

复制代码
CSRF_TRUSTED_ORIGINS=[“网站域名.com”]
相关推荐
我的xiaodoujiao1 小时前
从 0 到 1 搭建 Python 语言 Web UI自动化测试学习系列 15--二次开发--封装公共方法 3
python·学习·测试工具
AI视觉网奇1 小时前
pyqt 触摸屏监听
开发语言·python·pyqt
香菜+1 小时前
python脚本加密之pyarmor
开发语言·python
Brian Xia1 小时前
# tchMaterial-parser 入门指南
python·ai
啃啃大瓜1 小时前
常用库函数
开发语言·python
楼田莉子2 小时前
python学习:爬虫+项目测试
后端·爬虫·python·学习
总有刁民想爱朕ha2 小时前
Python自动化从入门到实战(17)python flask框架 +Html+Css开发一个实用的在线奖状生成器
python·flask·自动化·在线奖状生成器
修炼室2 小时前
如何将Python脚本输出(含错误)全量保存到日志文件?实战指南
开发语言·python
@LetsTGBot搜索引擎机器人3 小时前
用 Python 打造一个 Telegram 二手交易商城机器人
开发语言·python·搜索引擎·机器人·.net·facebook·twitter
kunge1v54 小时前
学习爬虫第三天:数据提取
前端·爬虫·python·学习