Can't login into admin URL on production with Django 4

787 views Asked by At

Can't seem to login into Django admin URL on my production but it works fine on my local. For context, currently my site does not have SSL. Debug is set to False as well.

This was working prior to Django 4 upgrade (was previously on Django 3.08)

mysite.com/admin keeps redirecting to mysite.com/admin/login/?next=/admin/ with a 500 error.

2

There are 2 answers

0
6ixpaths On BEST ANSWER

SOLVED

After going through my Django server logs it turned out being a missing packaged called tzdata. I had my timezone set to UTC so it was causing an error when accessing the admin panel.

My settings.py regarding timzones

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

Thanks everyone for their thoughts!

2
Jonas Blatt On

Add your origin (domain) to the CSRF_TRUSTED_ORIGINS variable in the settings.py file.

CSRF_TRUSTED_ORIGINS = [
    'http://my.domain.com:8000'
]

See https://docs.djangoproject.com/en/4.0/releases/4.0/#csrf-trusted-origins-changes-4-0