英文:
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']
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论