Search code examples
nginxdjango-admincsrfcsrf-token

CSRF verification failed. Request aborted


The only help towards this I can get is

It was working all day and all of a sudden this error starting popping up.

"Reason given for failure: CSRF cookie not set."

Turning debug to TRUE gives me nothing more. I see no errors in nginx either.

I have set CSRF_TRUSTED_ORIGINS

DEBUG = False

CSRF_TRUSTED_ORIGINS = ['http://.*', 'http://example.com', 'http://example.com']

HTTPS Settings

SESSION_COOKIE_SECURE = True

CSRF_COOKIE_SECURE = False

SECURE_SSL_REDIRECT = False

HSTS Settings

SECURE_HSTS_SECONDS = 31536000

SECURE_HSTS_PRELOAD = True

SECURE_HSTS_INCLUDE_SUBDOMAINS = True


Solution

  • FIXED:

    I checked gunicorn status using:

     sudo systemctl status gunicorn
    

    It gave me an error regarding my IP address needed adding to allowed hosts.

    If error still persists:

    sudo systemctl restart gunicorn