Привет, вот ошибка
повышение ImproperlyConfigured («Параметр SECRET_KEY не должен быть пустым.») django .core.exceptions.ImproperlyConfigured: параметр SECRET_KEY не должно быть пустым.
, когда я удаляю ЯЗЫКИ из файла настроек, затем он работает, в противном случае выдает ошибку, я пытался, но не смог ее устранить, помогите.
Структура кода - config-settings-base.py, local.py, production.py. Я устанавливаю ЯЗЫКИ в base.py. вот код настройки base.py
```
import os
from django.utils.translation import gettext as _
import environ
from django.urls import reverse_lazy
env = environ.Env()
ROOT_DIR = environ.Path(__file__) - 3
APPS_DIR = ROOT_DIR.path('userpeek')
READ_DOT_ENV_FILE = env.bool('DJANGO_READ_DOT_ENV_FILE', default=True)
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tango_with_django.settings')
if READ_DOT_ENV_FILE:
# OS environment variables take precedence over variables from .env
env_file = str(ROOT_DIR.path('.env'))
env.read_env(env_file)
ENV = env
application_name = env('APPLICATION_NAME')
LOG_DIR = env('LOG_DIR')
FILE = application_name + '.log'
DEBUG = env.bool('DJANGO_DEBUG', False)
# Local time zone. Choices are
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# though not all of them may be available with every OS.
# In Windows, this must be set to your system time zone.
# SECURITY WARNING: keep the secret key used in production secret!
USE_THOUSAND_SEPARATOR = True
# DATABASES
# ------------------------------------------------------------------------------
# DATABASE_ROUTERS = ['manager.router.DatabaseAppsRouter']
# DATABASE_ROUTERS = ['klm.application.router.FailoverRouter']
DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.sqlite3',
# 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
# }
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': env('DB_NAME'),
'HOST': env('DB_HOST'),
'PORT': env('DB_PORT', cast=int),
'USER': env('DB_USER'),
'PASSWORD': env('DB_PASSWORD'),
}
}
# URLS
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#root-urlconf
ROOT_URLCONF = 'config.urls'
# https://docs.djangoproject.com/en/dev/ref/settings/#wsgi-application
WSGI_APPLICATION = 'config.wsgi.application'
# APPS
# ------------------------------------------------------------------------------
# STATIC FILE CONFIGURATION
TIME_ZONE = 'UTC'
# https://docs.djangoproject.com/en/dev/ref/settings/#site-id
SITE_ID = 1
# https://docs.djangoproject.com/en/dev/ref/settings/#use-i18n
USE_I18N = True
# https://docs.djangoproject.com/en/dev/ref/settings/#use-l10n
USE_L10N = True
# https://docs.djangoproject.com/en/dev/ref/settings/#use-tz
USE_TZ = True
#
LANGUAGE_CODE = 'es'
LANGUAGES = (
('en', _('English')),
('es', _('Spanish')),
)
LOCALE_PATHS = (
os.path.join(str(ROOT_DIR), 'locale'),
)
print(LOCALE_PATHS)
# https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps
# PROJECT_APPS = env.list('PROJECT_APPS')
# THIRD_PARTY_APPS = env.list('THIRD_PARTY_APPS')
# REST_FRAME_WORK_APPS = env.list('REST_FRAME_WORK_APPS')
# ALL_AUTH_APPS = env.list('ALL_AUTH_APPS')
# INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + \
# REST_FRAME_WORK_APPS + ALL_AUTH_APPS + PROJECT_APPS
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'corsheaders',
'django.contrib.messages',
'django.contrib.staticfiles',
'crispy_forms',
'compressor',
'chargeover',
'rest_framework',
'rest_framework.authtoken',
'django.contrib.sites',
'user',
'profile',
'subscriptions',
'test',
]
# middleware classes we can add custom classes here also
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
# 'django.middleware.common.BrokenLinkEmailsMiddleware', # to mail admin when error comes
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'corsheaders.middleware.CorsPostCsrfMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
# 'django.middleware.locale.LocaleMiddleware',
# 'user.custom_middleware.middleware.RefreshTokenMiddleware',
]
# CORS_ORIGIN_ALLOW_ALL = False
# #
# CORS_ORIGIN_WHITELIST = [
# "http://localhost:4200",
# ]
# A list of HTTP verbs that are allowed for the actual request. Defaults to:
CORS_ORIGIN_ALLOW_ALL = True
CORS_ALLOW_CREDENTIALS = True
CORS_ALLOW_METHODS = env.list('CORS_ALLOW_METHODS')
CORS_ALLOW_HEADERS = env.list('CORS_ALLOW_HEADERS')
# auth password validation handler
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',
},
]
# rest_framework pemission and authentication classes handler
REST_FRAMEWORK = {
# 'EXCEPTION_HANDLER': 'rest_framework.views.exception_handler',
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework.authentication.TokenAuthentication',
# 'rest_framework.authentication.BasicAuthentication',
'rest_framework.authentication.SessionAuthentication',
],
'DEFAULT_PERMISSION_CLASSES': [
'rest_framework.permissions.IsAuthenticated',
],
}
# add custom register serializer
# REST_AUTH_REGISTER_SERIALIZERS = {
# 'REGISTER_SERIALIZER': 'user.serializer.CustomRegisterSerializer',
# }
AUTHENTICATION_BACKENDS = [
# 'django.contrib.auth.backends.ModelBackend',
'user.authentication.login_authentication.EmailBackend',
]
# AUTHENTICATION_BACKENDS = (
# # default
# 'django.contrib.auth.backends.ModelBackend',
# # email login
# 'allauth.account.auth_backends.AuthenticationBackend',
# )
# User Account handle configuration
""" singup email confirmation """
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_EMAIL_VERIFICATION = 'mandatory'
ACCOUNT_AUTHENTICATION_METHOD = "email"
ACCOUNT_CONFIRM_EMAIL_ON_GET = True
# ACCOUNT_USERNAME_REQUIRED = False
# ACCOUNT_UNIQUE_EMAIL = True
# after click on link of registation this will be redirect
# ACCOUNT_EMAIL_CONFIRMATION_ANONYMOUS_REDIRECT_URL = reverse_lazy('account_confirm_complete')
# ACCOUNT_EMAIL_CONFIRMATION_AUTHENTICATED_REDIRECT_URL = reverse_lazy('account_confirm_complete')
# ------------------------------------------------------------------------------
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.0/howto/static-files/
MEDIA_ROOT = str(ROOT_DIR('media'))
COMPRESS_ENABLED = os.environ.get('COMPRESS_ENABLED', False)
# See: https://docs.djangoproject.com/en/dev/ref/settings/#media-url
MEDIA_URL = '/media/'
# Static file Setup
STATIC_ROOT = str(ROOT_DIR('static'))
# See: https://docs.djangoproject.com/en/dev/ref/settings/#static-url
STATIC_URL = '/static/'
# See: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#std:setting-STATICFILES_DIRS
STATICFILES_DIRS = [
str(ROOT_DIR.path('staticfiles')),
]
# See: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#staticfiles-finders
STATICFILES_FINDERS = [
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'compressor.finders.CompressorFinder',
]
ACCOUNT_ADAPTER = env('ACCOUNT_ADAPTER')
URL_FRONT = env('URL_FRONT')
# TEMPLATES
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#templates
TEMPLATES = [
{
# https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-TEMPLATES-BACKEND
'BACKEND': 'django.template.backends.django.DjangoTemplates',
# https://docs.djangoproject.com/en/dev/ref/settings/#template-dirs
'DIRS': [
str(APPS_DIR.path('templates')),
],
'OPTIONS': {
# https://docs.djangoproject.com/en/dev/ref/settings/#template-debug
'debug': DEBUG,
# https://docs.djangoproject.com/en/dev/ref/settings/#template-loaders
# https://docs.djangoproject.com/en/dev/ref/templates/api/#loader-types
'loaders': [
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
],
# https://docs.djangoproject.com/en/dev/ref/settings/#template-context-processors
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.template.context_processors.i18n',
'django.template.context_processors.media',
'django.template.context_processors.static',
'django.template.context_processors.tz',
'django.contrib.messages.context_processors.messages',
],
},
},
]
# http://django-crispy-forms.readthedocs.io/en/latest/install.html#template-packs
CRISPY_TEMPLATE_PACK = 'bootstrap4'
# FIXTURES
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#fixture-dirs
# FIXTURE_DIRS = (
# str(APPS_DIR.path('fixtures')),
# )
# EMAIL
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#email-backend
EMAIL_BACKEND = env('DJANGO_EMAIL_BACKEND', default='django.core.mail.backends.smtp.EmailBackend')
# ADMIN
# ------------------------------------------------------------------------------
# Django Admin URL.
ADMIN_URL = 'admin/'
# https://docs.djangoproject.com/en/dev/ref/settings/#admins
ADMINS = [
("""Rahul Kumar""", 'rahul.kumar2@wildnettechnologies'),
]
# https://docs.djangoproject.com/en/dev/ref/settings/#managers
MANAGERS = ADMINS
""" Session management """
SESSION_EXPIRE_AT_BROWSER_CLOSE = env('SESSION_EXPIRE_AT_BROWSER_CLOSE')
SESSION_COOKIE_AGE = int(env('SESSION_COOKIE_AGE'))
SESSION_SAVE_EVERY_REQUEST = env('SESSION_SAVE_EVERY_REQUEST')
# Your stuff...
# ------------------------------------------------------------------------------
```
And here is local.py
```from .base import * # noqa
from .base import env
# GENERAL
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#debug
DEBUG = env.bool('DJANGO_DEBUG', default=False)
TEMPLATES[0]['OPTIONS']['debug'] = DEBUG
ENV = env
SECRET_KEY = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
# https://docs.djangoproject.com/en/dev/ref/settings/#secret-key
# SECURITY WARNING: keep the secret key used in production secret!
# https://docs.djangoproject.com/en/dev/ref/settings/#allowed-hosts
ALLOWED_HOSTS = env.list('ALLOWED_HOSTS')
INSTALLED_APPS += ['django_extensions']
# CACHES
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#caches
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
'LOCATION': ''
}
}
# TEMPLATES
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#templates
TEMPLATES[0]['OPTIONS']['debug'] = DEBUG # noqa F405
# EMAIL
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#email-backend
DEFAULT_FROM_EMAIL = env('EMAIL_HOST_USER')
EMAIL_BACKEND = env('DJANGO_EMAIL_BACKEND')
EMAIL_HOST = env('EMAIL_HOST')
EMAIL_PORT = int(env('EMAIL_PORT'))
EMAIL_HOST_USER = env('EMAIL_HOST_USER')
EMAIL_HOST_PASSWORD = env('EMAIL_HOST_PASSWORD')
SITE_ID = env('SITE_ID')
EMAIL_USE_TLS = env('EMAIL_USE_TLS')
# django-debug-toolbar
# ------------------------------------------------------------------------------
# https://django-debug-toolbar.readthedocs.io/en/latest/installation.html#prerequisites
# https://django-debug-toolbar.readthedocs.io/en/latest/installation.html#middleware
# MIDDLEWARE += ['debug_toolbar.middleware.DebugToolbarMiddleware'] # noqa F405
# https://django-debug-toolbar.readthedocs.io/en/latest/configuration.html#debug-toolbar-config
# django-extensions
# ------------------------------------------------------------------------------
# https://django-extensions.readthedocs.io/en/latest/installation_instructions.html#configuration
# Your stuff...
# ------------------------------------------------------------------------------
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},
'formatters': {
'verbose': {
'format': '%(levelname)s %(asctime)s %(module)s '
'%(process)d %(thread)d %(message)s'
},
},
'handlers': {
# 'mail_admins': {
# 'level': 'ERROR',
# 'filters': ['require_debug_false'],
# 'class': 'django.utils.log.AdminEmailHandler'
# },
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'verbose',
},
'file': {
'level': 'DEBUG',
'filename': os.path.join(LOG_DIR, FILE),
'class': 'logging.FileHandler',
'formatter': 'verbose'
},
'applogfile': {
'level': 'INFO',
'class': 'logging.FileHandler',
'filename': os.path.join(LOG_DIR, FILE),
'formatter': 'verbose'
},
},
'loggers': {
'django.request': {
'handlers': ['applogfile', 'file'],
'level': 'ERROR',
'propagate': True
},
'django.security.DisallowedHost': {
'level': 'ERROR',
'handlers': [],
'propagate': False
},
'user': {
'handlers': ['applogfile', 'file'],
'level': 'DEBUG',
'propagate': True,
},
'profile': {
'handlers': ['applogfile', 'file'],
'level': 'DEBUG',
'propagate': True,
},
},
'test': {
'handlers': ['applogfile', 'file'],
'level': 'DEBUG',
'propagate': True,
},
'accounts': {
'handlers': ['applogfile', 'file'],
'level': 'DEBUG',
'propagate': True,
},
}```