本番環境でdjangoの管理画面にログインできません。

settings.py

1DEBUG = False 2 3ALLOWED_HOSTS = ['IPアドレス','ドメイン名'] 4CSRF_TRUSTED_ORIGINS = ['https://ドメイン名'] 5SESSION_COOKIE_DOMAIN = 'ドメイン名' 6 7INSTALLED_APPS = [ 8 'django.contrib.sites', 9 'allauth', 10 'allauth.account', 11 'allauth.socialaccount', 12 'django.contrib.admin', 13 'django.contrib.auth', 14 'django.contrib.contenttypes', 15 'django.contrib.sessions', 16 'django.contrib.messages', 17 'django.contrib.staticfiles', 18 'アプリ名', 19 'accounts', 20] 21 22MIDDLEWARE = [ 23 'django.middleware.security.SecurityMiddleware', 24 'django.contrib.sessions.middleware.SessionMiddleware', 25 'django.middleware.common.CommonMiddleware', 26 'django.middleware.csrf.CsrfViewMiddleware', 27 'django.contrib.auth.middleware.AuthenticationMiddleware', 28 'django.contrib.messages.middleware.MessageMiddleware', 29 'django.middleware.clickjacking.XFrameOptionsMiddleware', 30 "allauth.account.middleware.AccountMiddleware", 31] 32 33SESSION_ENGINE = 'django.contrib.sessions.backends.cache' 34 35ROOT_URLCONF = 'main.urls' 36 37TEMPLATES = [ 38 { 39 'BACKEND': 'django.template.backends.django.DjangoTemplates', 40 'DIRS': [BASE_DIR / "templates"], 41 'APP_DIRS': True, 42 'OPTIONS': { 43 'context_processors': [ 44 'django.template.context_processors.debug', 45 'django.template.context_processors.request', 46 'django.contrib.auth.context_processors.auth', 47 'django.contrib.messages.context_processors.messages', 48 ], 49 }, 50 }, 51] 52 53WSGI_APPLICATION = 'main.wsgi.application' 54 55DATABASES = { 56 'default': { 57 'ENGINE': 'django.db.backends.postgresql_psycopg2', 58 'NAME': 'データベース名', 59 'USER': 'ユーザー名', 60 'PASSWORD': os.environ.get("pass_db"), 61 'HOST': 'localhost', 62 'PORT': '5432', 63 } 64 } 65 66 67AUTH_PASSWORD_VALIDATORS = [] 68 69 70 71LANGUAGE_CODE = 'ja' 72 73TIME_ZONE = 'Asia/Tokyo' 74 75USE_I18N = True 76 77USE_TZ = True 78 79STATIC_URL = '/static/' 80STATIC_ROOT = PARENT_DIR / 'site/public/static' 81 82MEDIA_ROOT = PARENT_DIR / 'site/public/media' 83MEDIA_URL = '/media/' 84 85 86 87DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' 88 89AUTH_USER_MODEL = 'accounts.User' 90 91 92AUTHENTICATION_BACKENDS = [ 93 'django.contrib.auth.backends.ModelBackend', 94 'allauth.account.auth_backends.AuthenticationBackend', 95] 96 97SITE_ID = 1 98 99 100ACCOUNT_FORMS = { 101 'signup': 'accounts.forms.CustomSignupForm', 102 'login': 'accounts.forms.CustomLoginForm', 103 'reset_password': 'accounts.forms.CustomResetPasswordForm', 104 'reset_password_from_key': 'accounts.forms.CustomResetPasswordKeyForm', 105} 106 107ACCOUNT_USER_MODEL_USERNAME_FIELD = None 108ACCOUNT_USERNAME_REQUIRED = False 109ACCOUNT_AUTHENTICATION_METHOD = 'email' 110ACCOUNT_EMAIL_REQUIRED = True 111 112from django.urls import reverse_lazy 113LOGIN_REDIRECT_URL = reverse_lazy('mypage') 114ACCOUNT_LOGOUT_REDIRECT_URL = reverse_lazy("top") 115ACCOUNT_EMAIL_VERIFICATION = "mandatory" 116ACCOUNT_LOGOUT_ON_GET = True 117 118 119EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' 120EMAIL_HOST = 'smtp.gmail.com' 121EMAIL_PORT = 587 122EMAIL_USE_TLS = True 123EMAIL_HOST_USER = 'メールアドレス' 124EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_HOST_PASSWORD') 125DEFAULT_FROM_EMAIL = EMAIL_HOST_USER

コメントを投稿

0 コメント