I deployed my django project on Azure and when I try to login via admin login it returns csrf error. My site runs good but it returns that error which I can not understand. Before azure I have used another cloud hosting It worked without any errors. I already tried some solutions on the net but none of them worked for me.
Here is the error code.
“”"
Forbidden (403)
CSRF verification failed. Request aborted.
Help
Reason given for failure:
Origin checking failed - “the url deleted” does not match any trusted origins.
“”
This is my settings.py file
“”
“”"
Django settings for coin project.
Generated by ‘django-admin startproject’ using Django 5.0.2.
“”"
from pathlib import Path
import os
Build paths inside the project like this: BASE_DIR / ‘subdir’.
BASE_DIR = Path(file).resolve().parent.parent
SECURITY WARNING: don’t run with debug turned on in production!
#DEBUG = True
DEBUG = os.environ.get(‘DJANGO_DEBUG’, ‘’) != ‘False’
ALLOWED_HOSTS = [‘*’]
Application definition
INSTALLED_APPS = [
‘django.contrib.admin’,
‘django.contrib.auth’,
‘django.contrib.contenttypes’,
‘django.contrib.sessions’,
‘django.contrib.messages’,
‘django.contrib.staticfiles’,
‘main’,
]
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’,
]
ROOT_URLCONF = ‘coin.urls’
TEMPLATES = [
{
‘BACKEND’: ‘django.template.backends.django.DjangoTemplates’,
‘DIRS’: [BASE_DIR / ‘templates’ ],
‘APP_DIRS’: True,
‘OPTIONS’: {
‘context_processors’: [
‘django.template.context_processors.debug’,
‘django.template.context_processors.request’,
‘django.contrib.auth.context_processors.auth’,
‘django.contrib.messages.context_processors.messages’,
],
},
},
]
WSGI_APPLICATION = ‘coin.wsgi.application’
DATABASES = {
‘default’: {
‘ENGINE’: ‘django.db.backends.sqlite3’,
‘NAME’: BASE_DIR / ‘db.sqlite3’,
}
}
AUTH_PASSWORD_VALIDATORS = [
{
‘NAME’: ‘django.contrib.auth.password_validation.UserAttributeSimilarityValidator’,
},
{
‘NAME’: ‘django.contrib.auth.password_validation.MinimumLengthValidator’,
},
{
‘NAME’: ‘django.contrib.auth.password_validation.CommonPasswordValidator’,
},
{
‘NAME’: ‘django.contrib.auth.password_validation.NumericPasswordValidator’,
},
]
LANGUAGE_CODE = ‘en-us’
TIME_ZONE = ‘Europe/Istanbul’
USE_I18N = True
USE_TZ = True
STATIC_URL = ‘/static/’
STATICFILES_DIRS=(os.path.join(BASE_DIR,‘staticfiles/’),)
STATIC_ROOT = os.path.join(BASE_DIR, ‘static’)
CSRF_TRUSTED_ORIGINS = [‘https://dangoapp-ena2g3bkbfepfu.germanywestcentral-01.azurewebsites.net/’]
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
STATIC_URL = ‘static/’
DEFAULT_AUTO_FIELD = ‘django.db.models.BigAutoField’
LOGIN_URL = ‘/accounts/login/’
LOGIN_REDIRECT_URL = ‘/’
LOGOUT_REDIRECT_URL = ‘/login/’ # Optional for logout