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”]
相关推荐
ServBay10 小时前
9 个 Python 第三方库推荐,不用 AI 都好像多出一个团队
后端·python
用户83562907805110 小时前
如何使用 Python 添加和管理 Excel 批注(完整示例)
后端·python
用户83562907805110 小时前
使用 Python 管理 Excel 工作表:创建、复制、删除与重命名
后端·python
荣码19 小时前
LangGraph多Agent协作:3个Agent干活比1个强,但我踩了4个坑
java·python
用户8356290780511 天前
Python 操作 PDF 附件:添加、查看与管理指南
后端·python
宇宙之一粟2 天前
乐企版式文件生成平台
java·后端·python
学测绘的小杨2 天前
CompassFusion:一个从 GNSS 到 GNSS/INS 组合导航的独立工程包
python
zzzzzz3103 天前
当产品经理说这个很简单:我用Python自动化处理奇葩需求的实战指南
python·pycharm·产品经理
雪隐3 天前
个人电脑玩AI-06让5060 Ti给你打工——不光能画画,Qwen3-TTS还能学人说话,连我老板都信了!
人工智能·后端·python
兵慌码乱3 天前
面向桌面端的资产管理系统分层架构设计与核心模块实现
python·系统架构·sqlite·pyqt5·数据库设计·桌面应用开发·mvc架构