Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

进入后台后提示禁止访问? #16

Open
horizon365 opened this issue Aug 28, 2024 · 5 comments
Open

进入后台后提示禁止访问? #16

horizon365 opened this issue Aug 28, 2024 · 5 comments
Labels
help wanted Extra attention is needed

Comments

@horizon365
Copy link

图片

@Deali-Axy
Copy link
Owner

Deali-Axy commented Aug 28, 2024

检查浏览器是否开启cookie功能,可以尝试切换浏览器,更改启动端口。

关于CSRF的详情可以参考官方文档:https://docs.djangoproject.com/zh-hans/5.0/ref/csrf/

@Deali-Axy Deali-Axy added the help wanted Extra attention is needed label Aug 28, 2024
@horizon365
Copy link
Author

您本地不能复现吗?我试过你说的放大,都不能解决。我是个老Django了,但是这种问题还是比较头痛

@Deali-Axy
Copy link
Owner

我在本地运行没有遇到这个问题。

倒是在部署时有遇到过:以debug模式+ python manage.py runserver 模式在服务器上运行时(绑定域名访问)也遇到过,不过改成 daphne 正式部署就正常了。

@horizon365
Copy link
Author

问题解决了,在 src/config/settings/components/common.py 文件中加入
CSRF_TRUSTED_ORIGINS = ['http://127.0.0.1:9876']
就可以了。这是Django新版本必须要求的配置。

@Deali-Axy
Copy link
Owner

感谢提供这个方案,响应的django文档: https://docs.djangoproject.com/zh-hans/5.1/ref/settings/#csrf-trusted-origins

我暂时还没有研究更好的解决方案,如果您有好的方案,可以发起Pull Request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants