简体   繁体   English

部署时无法使用我的超级用户帐户登录 Django admin,显示 CSRF 错误 403 禁止

[英]Cannot Login to Django admin with my superuser account when it is on Deployment, showing CSRF error 403 forbidden

I am super newbie on DJango and Programming.我是 DJango 和编程的超级新手。

I made a backend server with django and deployed successfully on "render.com". 我用 django 创建了一个后端服务器,并成功部署在“render.com”上。

I can approach to admin login screen but cannot login to it with my superuser ID. 我可以访问管理员登录屏幕,但无法使用我的超级用户 ID 登录。

[it worked in runserver perfect but does not work on deployment... showing error below:-( ] [它在 runserver 中完美运行,但在部署时不起作用...显示以下错误:-( ]


Forbidden (403)禁止 (403)

CSRF verification failed. CSRF 验证失败。 Request aborted. 请求中止。

You are seeing this message because this site requires a CSRF cookie when submitting forms. This cookie is required for security reasons, to ensure that your browser is not being hijacked by third parties. 您看到此消息是因为此站点在提交 forms 时需要 CSRF cookie。出于安全原因需要此 cookie,以确保您的浏览器不被第三方劫持。

If you have configured your browser to disable cookies, please re-enable them, at least for this site, or for 'same-origin' requests. 如果您已将浏览器配置为禁用 cookies,请重新启用它们,至少对于本网站或“同源”请求。


I googled some articles about it.我用谷歌搜索了一些关于它的文章。 and they told me that I have to add他们告诉我必须添加

CSRF_TRUSTED_ORIGINS= ["mydomain"]

on settings.py在设置.py

Here is the questions...这是问题...

Q1. Q1。 Do I have to put my frontend domain or backend domain in "mydomain"?我是否必须将我的前端域或后端域放在“mydomain”中?

Q2. Q2。 Some articles said that I have to add有文章说我要补充

CSRF_COOKIE_SECURE = False

in my settings.py too??在我的 settings.py 中也是?

Here are my few suggestions kindly note that my use of Django is also limited but the time I have encountered this issue in regards to question one use your frontend domain but also edit your syntax to have single quotation marks than double quotation marks ( I see you're using double quotation marks) as illustrated below:-这是我的一些建议,请注意我对 Django 的使用也是有限的,但我遇到这个问题的时间是关于问题一使用你的前端域但也编辑你的语法以使用单引号而不是双引号(我看到你了'使用双引号)如下图所示:-

CSRF_TRUSTED_ORIGINS = ['https://*.your_domain.com','https://*.127.0.0.1']

About Question two Sometimes it's actually your web browser try using incognito mode and yes you have to set关于问题二 有时实际上是您的 web 浏览器尝试使用隐身模式,是的,您必须设置

CSRF_COOKIE_SECURE = False

In your settings file more details on this answer在您的设置文件中有关此答案的更多详细信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM