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 分钟前
Vscode解决python venv虚拟环境问题
ide·vscode·python
2401_891482176 分钟前
Python Web爬虫入门:使用Requests和BeautifulSoup
jvm·数据库·python
超越自我肖6 分钟前
python--while循环案例九九乘法表
python
油泼辣子多加10 分钟前
【PY】数据处理函数
python·深度学习·机器学习·数据分析
超越自我肖11 分钟前
python--while循环的嵌套应用
python
DeepModel26 分钟前
【概率分布】正态分布(高斯分布)原理、可视化与机器学习实战
python·算法·概率论
坚持学习前端日记33 分钟前
ComfyUI模型管理与集成方案
前端·人工智能·python
Flittly36 分钟前
【从零手写 ClaudeCode:learn-claude-code 项目实战笔记】(8)Background Tasks (后台任务)
python·agent
Flittly38 分钟前
【从零手写 ClaudeCode:learn-claude-code 项目实战笔记】(7)Task System (任务系统)
python·agent
代码探秘者40 分钟前
【大模型应用】2.RAG详细流程
java·开发语言·人工智能·后端·python