“CSRF Token issue in Django app deployed in Railway, ‘CSRF verification failed. Request aborted.'”

huangapple go评论61阅读模式
英文:

CSRF Token issue in Django app deployed in Railway, "CSRF verification failed. Request aborted."

问题

我遇到的错误是“CSRF验证失败。请求已中止。”
错误图像

该网站在本地运行正常,没有问题。

我尝试在我的settings.py中添加了此基本域,但仍然遇到相同的错误:
输入图像描述

我还尝试了这个修复方法,并重新加载了requirements.txt,但没有效果:
输入图像描述

任何帮助将不胜感激。

英文:

The error I get is "CSRF verification failed. Request aborted."
Error Image

The site works fine and there are no issues on localhost

I tried adding this base domain in my settings.py but I am still getting the same error:
enter image description here

I also tried this fix, and reloaded the requirements.txt but to no avail:
enter image description here

Any help would be appreciated.

答案1

得分: 0

CSRF_TRUSTED_ORIGINS 必须按照以下方式提供受信任的来源(如果您使用的是 Django 4.0 或更高版本):

CSRF_TRUSTED_ORIGINS 必须包括方案和主机,适用于 Django 4.0 及更高版本。如果您使用的是 Django 3.2 及以下版本,则不需要这样做:

CSRF_TRUSTED_ORIGINS = ['https://web-production-716d.up.railway.app']
英文:

You need to provide the trusted origins like this (if you are using Django 4.0 or above)

CSRF_TRUSTED_ORIGINS must include scheme and host, for Django 4.0 and above. If you are using Django 3.2 and below, this is not required

CSRF_TRUSTED_ORIGINS = ['https://web-production-716d.up.railway.app']

huangapple
  • 本文由 发表于 2023年6月19日 22:35:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/76507641.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定