CSRF Verification Failed - CSRF_TRUSTED_ORIGINS doesn’t work

I have tried to compare your config to mine. I don’t actually know what’s wrong here, but I had a similar problem that I finally fixed. Here are a couple of differences I noticed between your config and mine:

That is the wrong slash. Try:

FILE_SERVER_ROOT = 'https://file.example.com/seafhttp'

I also have these extra lines you don’t have:

ALLOWED_HOSTS = ['.example.com']

# Whether to use a secure cookie for the CSRF cookie
# https://docs.djangoproject.com/en/3.2/ref/settings/#csrf-cookie-secure
CSRF_COOKIE_SECURE = True

# The value of the SameSite flag on the CSRF cookie
# https://docs.djangoproject.com/en/3.2/ref/settings/#csrf-cookie-samesite
CSRF_COOKIE_SAMESITE = 'Strict'

# https://docs.djangoproject.com/en/3.2/ref/settings/#csrf-trusted-origins
CSRF_TRUSTED_ORIGINS = ['https://file.example.com']
1 Like