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”]
相关推荐
田里的水稻4 小时前
PyTorch-Dataset\DataLoader数据加载
人工智能·pytorch·python
卷无止境4 小时前
Python 3.14 自由线程:拆掉 GIL 之后,我们到底得到了什么
后端·python
染指11104 小时前
147.Agent-LangGraph归并函数
开发语言·人工智能·python·langchain·agents
小白学大数据4 小时前
逆向分析短视频平台 a_bogus 参数:从 JavaScript 混淆到 Python 复现
javascript·python·音视频
外收内放4 小时前
数据分析(数据清洗)
python·学习·数据分析
小小张说故事4 小时前
Python 的 True + True 为什么等于 2?bool 是 int 子类,这个设计坑了多少人
python
神仙别闹5 小时前
基于Python实现自动化测试作业—图像增广方案
图像处理·python·计算机视觉
坊钰5 小时前
【LangGraph框架入门级】12. 人机交互:interrupt 中断与 Command 恢复
开发语言·数据库·python·人机交互·ai编程·langgraph
把我格子衫拿来5 小时前
四元数为什么突然变号?旋转表示、SLERP 与位姿插值避坑
python·机器人·坐标变换·四元数·slerp
Chasing__Dreams5 小时前
python杂识--24--Nuitak打包exe
开发语言·python