djangodjango-csrfcsrf-tokenrailway

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


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.


Solution

  • 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']