When I try to login to the django admin which is hosted on the server getting error
Forbidden (CSRF cookie not set.): /admin/login/
I can view the website and navigate but can’t login to it. I Didn’t receive this error while testing when django was running on local machine but getting it when I deploy it to the server.
Here is my settings.py
configuration
IP_ADDRESS = "HERE_WILL_BE_THE_IP_ADDRESS"
ALLOWED_HOSTS = [IP_ADDRESS, f"{IP_ADDRESS}:8000"]
CSRF_TRUSTED_ORIGINS = [f"http://{IP_ADDRESS}:8000/", f"http://{IP_ADDRESS}/", "http://127.0.0.1/", "http://127.0.0.1:8000/", "http://*.127.0.0.1/"]
INSTALLED_APPS = [
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"users",
"django.contrib.sites",
"allauth",
"allauth.account",
"allauth.socialaccount",
"allauth.socialaccount.providers.google",
]
MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
]
SECURE_REFERRER_POLICY = "no-referrer-when-downgrade"
CSRF_COOKIE_SECURE = True
SESSION_COOKIE_SECURE = False
CSRF_COOKIE_SAMESITE = 'None'
SESSION_COOKIE_SAMESITE = 'None'
# SMTP CONFIGURATION
EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = PRO_SETTINGS["email_address"]
EMAIL_HOST_PASSWORD = PRO_SETTINGS["email_pass"]
LOGIN_URL = 'login'
AUTHENTICATION_BACKENDS = [
'django.contrib.auth.backends.ModelBackend',
'allauth.account.auth_backends.AuthenticationBackend'
]
SOCIALACCOUNT_LOGIN_ON_GET = True
SOCIALACCOUNT_PROVIDERS = {
'google': {
'SCOPE': [
'profile',
'email',
],
'AUTH_PARAMS': {
'access_type': 'online',
},
'OAUTH_PKCE_ENABLED': True,
}
}
I want to login to django server. How can I resolve this issue?