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”]
相关推荐
qq_192779871 天前
Python多线程与多进程:如何选择?(GIL全局解释器锁详解)
jvm·数据库·python
naruto_lnq1 天前
NumPy入门:高性能科学计算的基础
jvm·数据库·python
工程师老罗1 天前
Pytorch中的优化器及其用法
人工智能·pytorch·python
2301_822365031 天前
实战:用Python分析某电商销售数据
jvm·数据库·python
luoluoal1 天前
基于python的人脸识别的酒店客房入侵检测系统(源码+文档)
python·mysql·django·毕业设计·源码
子午1 天前
【2026计算机毕设~AI项目】鸟类识别系统~Python+深度学习+人工智能+图像识别+算法模型
图像处理·人工智能·python·深度学习
流㶡1 天前
网络爬虫库与robots.txt规则
python·网络爬虫
2301_788756061 天前
Python在2024年的主要趋势与发展方向
jvm·数据库·python
阿部多瑞 ABU1 天前
`tredomb`:一个面向「思想临界质量」初始化的 Python 工具
前端·python·ai写作
u0109272711 天前
Python虚拟环境(venv)完全指南:隔离项目依赖
jvm·数据库·python