在mac os上执行迁移命令'python manage.py migrate'
时,出现以下错误
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/jeetpatel/final-tribute/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
utility.execute()
File "/Users/jeetpatel/final-tribute/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 356, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/jeetpatel/final-tribute/venv/lib/python2.7/site-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/jeetpatel/final-tribute/venv/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 61, in execute
super(Command, self).execute(*args, **options)
File "/Users/jeetpatel/final-tribute/venv/lib/python2.7/site-packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/Users/jeetpatel/final-tribute/venv/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 72, in handle
if not settings.DEBUG and not settings.ALLOWED_HOSTS:
File "/Users/jeetpatel/final-tribute/venv/lib/python2.7/site-packages/django/conf/__init__.py", line 56, in __getattr__
self._setup(name)
File "/Users/jeetpatel/final-tribute/venv/lib/python2.7/site-packages/django/conf/__init__.py", line 41, in _setup
self._wrapped = Settings(settings_module)
File "/Users/jeetpatel/final-tribute/venv/lib/python2.7/site-packages/django/conf/__init__.py", line 129, in __init__
raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.
我已经提到过SECRET_KEY =&#39; fooo&#39;在我的base.py文件中
base.py
import os
import smtplib
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
SITE_NAME = 'final-tribute'
# Allow all host headers
ALLOWED_HOSTS = []
# AUTH_PROFILE_MODULE = 'profiles.Profile'
LOGIN_REDIRECT_URL = '/profiles/'
LOGIN_URL = '/'
ADMINS = (
('Ab Rao', 'abc@abc.in')
)
MANAGERS = ADMINS
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/
# Application definition
DJANGO_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.postgres',
# 'social.apps.django_app.default',
)
THIRD_PARTY_APPS = (
'rest_framework',
'rest_framework.authtoken',
'social.apps.django_app.default',
'micawber.contrib.mcdjango',
'paypal.standard.ipn',
# 'django_extensions',
# 'storages',
)
LOCAL_APPS = (
'core',
'login',
'profiles',
'tributes',
'testimonials',
'anecdotes',
'family_tree',
'timeline',
'gallery',
'general',
'customauth',
'myapp'
)
INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS
MIDDLEWARE_CLASSES = (
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'core.get_username.RequestMiddleware'
)
ROOT_URLCONF = 'ft.urls'
HOST_URL = os.environ.get('HOST_URL')
WSGI_APPLICATION = 'ft.wsgi.application'
AUTH_USER_MODEL = 'customauth.User'
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',
],
},
},
]
# -------------------------------------------------------
#
# Settings to be set in local/prod/staging setting files
#
# --------------------------------------------------------
SECRET_KEY = "foo"
DEBUG = False
DATABASES = {
#'default': {
# 'ENGINE': 'django.db.backends.mysql',
# 'NAME': 'db',
# 'USER': 'user',
#'PASSWORD': 'db_user',
#'HOST': 'localhost',
#'PORT': '3306',
}
}
PAYPAL_TEST = True
# AWS Settings
AWS_QUERYSTRING_AUTH = False
AWS_ACCESS_KEY_ID = ""
AWS_SECRET_ACCESS_KEY = ""
AWS_STORAGE_BUCKET_NAME = 'finaltribute-dev'
MEDIA_URL = 'http://%s.s3.amazonaws.com/' % AWS_STORAGE_BUCKET_NAME
DEFAULT_FILE_STORAGE = "storages.backends.s3boto.S3BotoStorage"
# --------------------------------------------------------
# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'Asia/Kolkata'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Honor the 'X-Forwarded-Proto' header for request.is_secure()
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.7/howto/static-files/
STATIC_ROOT = os.path.join(BASE_DIR, 'static_root')
STATIC_URL = '/static/'
#MEDIA_ROOT = os.path.join(BASE_DIR, 'media_root')
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static')
]
# Rest framework settings
REST_FRAMEWORK = {
'PAGINATE_BY': 10,
'PAGINATE_BY_PARAM': 'page_size',
'MAX_PAGINATE_BY': 100,
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.BasicAuthentication',
),
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAdminUser',
),
'DEFAULT_FILTER_BACKENDS': (
'rest_framework.filters.DjangoFilterBackend',
),
}
# temp <- FIXME this needs to go into local/prod/staging files.
EMAIL_USE_TLS = True
EMAIL_HOST = os.environ.get('EMAIL_HOST')
EMAIL_HOST_USER = os.environ.get('EMAIL_HOST_USER')
EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_HOST_PASSWORD')
EMAIL_PORT = os.environ.get('EMAIL_PORT')
BASIC_WWW_AUTHENTICATION_USERNAME = "ftwalla"
BASIC_WWW_AUTHENTICATION_PASSWORD = "ftwalla"
BASIC_WWW_AUTHENTICATION = True
错误还提到了文件 init .py
的路径初始化的.py
from __future__ import absolute_import
另外我的manage.py看起来像这样 -
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
我尝试了几件事,包括导出SECRET_KEY =&#39; foo&#39;但没有任何问题。
runserver命令也会出现相同的错误。
答案 0 :(得分:1)
应用运行服务器或任何命令(包括迁移)时使用的设置。
示例:python manage.py runserver --settings=app.settings.local
答案 1 :(得分:0)
由于设置模块的循环依赖性(例如,在尝试加载设置模块的设置中加载的中间件类),可能会发生此错误。