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”]
相关推荐
Captain_Data5 分钟前
Python机器学习sklearn线性模型完整指南:LinearRegression/Ridge/Lasso详细代码注释
python·机器学习·数据分析·线性回归·sklearn
爱码小白8 分钟前
MySQL 单表查询练习题汇总
数据库·python·算法
北辰alk20 分钟前
全网最详实!Python 全家桶框架深度对比:从 Web 开发到 AI 应用,一篇打通选型关
python
xyz_CDragon1 小时前
OpenClaw Skills 完全指南:ClawHub 安装、安全避坑与自定义开发(2026)
人工智能·python·ai·skill·openclaw·clawhub
断眉的派大星1 小时前
pytorch中view和reshape的区别
人工智能·pytorch·python
程序员阿明1 小时前
spring boot3 集成jjwt(java-jwt)版本的
java·spring boot·python
Fleshy数模1 小时前
基于MediaPipe实现人体姿态与脸部关键点检测
python·opencv·计算机视觉
星马梦缘1 小时前
jupyter Kernel Disconnected崩溃的修复
ide·python·jupyter
Freak嵌入式1 小时前
MicroPython LVGL基础知识和概念:显示与多屏管理
开发语言·python·github·php·gui·lvgl·micropython
枕布响丸辣1 小时前
Python 操作 MySQL 数据库从入门到精通
数据库·python·mysql