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”]
相关推荐
Alkaid20776 分钟前
我把文件和脚本放一起了,Python 就是看不见?新手必看的绝对路径 vs 相对路径终极避坑指南
python·ai编程
SamChan9027 分钟前
Python+OpenCV检测PDF翻译后排版偏移:像素级格式一致性验证
python·opencv·ai·pdf·wpf
会博通·代码搬运工28 分钟前
双层PDF技术实现与档案数字化系统的API集成实践
数据库·人工智能·分布式·python·计算机视觉·api集成
健康平安的活着30 分钟前
java中批量查询+stream返回map提高查询效率
java·windows·python
无线通信科研笔记32 分钟前
IEEE TWC 2026 论文精读与完整复现|H-PASS:机械—电子双重可重构波束成形
论文阅读·人工智能·笔记·python·论文笔记
青 春 记 忆39 分钟前
零基础入门python35:Django用户登录与权限边界
python·django·后端开发
淼澄研学44 分钟前
LangChain构建Prompt模板解决Python长尾报错实操
python·langchain·prompt
枫叶v.1 小时前
DeepSeek Harness(DSH)插件开发保姆级教程:从 0 到 1 快速写出第一个插件
python
Htr_1 小时前
Python面向对象编程:类与对象基础
开发语言·python
muddjsv1 小时前
Python 神经网络入门:用 scikit-learn 完成 MLP 分类与回归
python·神经网络·scikit-learn