djangodjango-settingsdjango-csrf

Csrf token verification failing for admin form after using AbstractUser class in Deployement?


I am using Django 4.2.4 and created a class with Abstract User class for authentication in Django. Works fine on Localhost but when deployed the admin route is redirecting and csrf verification is failing with 403 Error.

https://rallys.azurewebsites.net/admin/login/?next=/admin/
ALLOWED_HOSTS = ['*']
CSRF_TRUSTED_ORIGINS = ['https://rallys.azurewebsites.net']
AUTH_USER_MODEL = 'home.User'

I have looked at modifying the Authenticate_user_model but the error persists.

I noticed that the passwords field is no longer hashed in the admin panel on local host except for the SuperUser I created using CLI.


Solution

  • As the url is redirecting the https is converting into an http in order to fix it i did inlcude the following in settings.py.

    SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')