All was working well before I split the settings (development, production). Now I am having an issue with the template doesn't exist. Here are my settings files:
base_settings.py
:
import os
from pathlib import Path
BASE_DIR = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)),
'../../'))
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'autoslug',
'accounts',
'stellar',
'stellar_sdk',
]
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 = 'stellarLedger.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': os.path.join(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 = 'stellarLedger.wsgi.application'
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'email username'
EMAIL_HOST_PASSWORD = 'password'
EMAIL_USE_TLS = True
LOGOUT_REDIRECT_URL = '/'
AUTH_USER_MODEL = "accounts.customUser"
# Database
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Password validation
# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators
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',
},
]
# Internationalization
# https://docs.djangoproject.com/en/3.2/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.2/howto/static-files/
STATIC_URL = '/static/'
# STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
development_settings.py
from .base_settings import *
SECRET_KEY = 'secret key'
DEBUG = True
ALLOWED_HOSTS = ['192.168.0.102', '127.0.0.1']
production_settings.py
from .base_settings import *
DEBUG = False
ALLOWED_HOSTS = ['mysite.com', 'ip.of.my.site', 'www.mysite.com', ]
What am I doing wrong here? The template that is not found is in root template directory.
here is my project structure:
You changed the default name of settings.py
. Revert back all the changes of settings.py
and add this line after DEBUG = True
:
productions_hosts = ['mysite.com', 'ip.of.my.site', 'www.mysite.com']
development_hosts = ['192.168.0.102', '127.0.0.1']
ALLOWED_HOSTS = development_hosts if DEBUG else productions_hosts
And one more thing, KEEP THE SECRET KEY SECRET!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.