CSRF token issue when upgrading Django to version 4.*

Question:

I was using the Django version 3, but then upgraded it to Django version 4(django==4.0.6).

After logging to admin panel of Django project, it said that CSRF token is invalid.
I found this link in Django documentation and tried to put such variable in settings.py:

ALLOWED_ORIGINS = ['https://*', 'http://*']

But it didn’t help. What am I doing wrong?

Asked By: Rostyslav Khudov

||

Answers:

ALLOWED_ORIGINS is not related to CSRF token. To fix problems related to your issue, you must specify the following setting for the project in production mode to settings.py module:

CSRF_TRUSTED_ORIGINS = [
        'https://subdomain.example.com',
        'https://*.blob.com',
        ...
    ]

For reading more information related to this topic you can read CSRF_TRUSTED_ORIGINS in django documentation.

Answered By: Javad Nikbakht
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.