我从github克隆了一个Django项目。但是当我运行python manage.py runserver
时,它显示了以下错误。如何解决它们?
python manage.py runserver
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/human-inside/.local/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/home/human-inside/.local/lib/python2.7/site-packages/django/core/management/__init__.py", line 303, in execute
settings.INSTALLED_APPS
File "/home/human-inside/.local/lib/python2.7/site-packages/django/conf/__init__.py", line 48, in __getattr__
self._setup(name)
File "/home/human-inside/.local/lib/python2.7/site-packages/django/conf/__init__.py", line 44, in _setup
self._wrapped = Settings(settings_module)
File "/home/human-inside/.local/lib/python2.7/site-packages/django/conf/__init__.py", line 92, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/home/human-inside/Desktop/web_project/parsifal/settings.py", line 18, in <module>
default = config('DATABASE_URL'))
File "/usr/local/lib/python2.7/dist-packages/decouple.py", line 198, in __call__
return self.config(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/decouple.py", line 77, in __call__
return self.get(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/decouple.py", line 64, in get
raise UndefinedValueError('%s option not found and default value was not defined.' % option)
decouple.UndefinedValueError: DATABASE_URL option not found and default value was not defined.
setting.py在这里:
from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS as TCP
from unipath import Path
import dj_database_url
from decouple import config, Csv
from mendeley import Mendeley
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
CSRF_COOKIE_SECURE = config('CSRF_COOKIE_SECURE', default=True, cast=bool)
SESSION_COOKIE_SECURE = config('SESSION_COOKIE_SECURE', default=True, cast=bool)
PROJECT_DIR = Path(__file__).parent
DEBUG = config('DEBUG', default=False, cast=bool)
TEMPLATE_DEBUG = DEBUG
DATABASES = {
'default': dj_database_url.config(
default = config('DATABASE_URL'))
}
ALLOWED_HOSTS = config('ALLOWED_HOSTS', cast=Csv())
ADMINS = (
('Vitor Freitas', 'vitorfs@gmail.com'),
)
MANAGERS = ADMINS
TIME_ZONE = 'UTC'
LANGUAGE_CODE = 'en-us'
USE_I18N = True
USE_L10N = True
USE_TZ = True
MEDIA_ROOT = PROJECT_DIR.parent.parent.child('media')
MEDIA_URL = '/media/'
FILE_UPLOAD_TEMP_DIR = '/tmp/'
FILE_UPLOAD_PERMISSIONS = 0644
FILE_UPLOAD_MAX_MEMORY_SIZE = 33554432
STATIC_ROOT = PROJECT_DIR.parent.parent.child('static')
STATIC_URL = '/static/'
STATICFILES_DIRS = (
PROJECT_DIR.child('static'),
)
SECRET_KEY = config('SECRET_KEY')
MIDDLEWARE_CLASSES = (
'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',
'django.middleware.security.SecurityMiddleware',
)
ROOT_URLCONF = 'parsifal.urls'
WSGI_APPLICATION = 'parsifal.wsgi.application'
TEMPLATE_DIRS = (
PROJECT_DIR.child('templates'),
)
TEMPLATE_CONTEXT_PROCESSORS = TCP + (
'django.core.context_processors.request',
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'django.contrib.humanize',
'parsifal.reviews',
'parsifal.reviews.planning',
'parsifal.reviews.conducting',
'parsifal.reviews.reporting',
'parsifal.reviews.settings',
'parsifal.account_settings',
'parsifal.activities',
'parsifal.authentication',
'parsifal.blog',
'parsifal.core',
'parsifal.help',
'parsifal.library',
'parsifal.search',
)
LOGIN_URL = '/signin/'
LOGOUT_URL = '/signout/'
EMAIL_BACKEND = config('EMAIL_BACKEND', default='django.core.mail.backends.smtp.EmailBackend')
EMAIL_FILE_PATH = PROJECT_DIR.parent.child('maildumps')
EMAIL_HOST = config('EMAIL_HOST')
EMAIL_PORT = config('EMAIL_PORT', cast=int)
EMAIL_HOST_USER = config('EMAIL_HOST_USER')
EMAIL_HOST_PASSWORD = config('EMAIL_HOST_PASSWORD')
EMAIL_USE_TLS = config('EMAIL_USE_TLS', cast=bool)
DEFAULT_FROM_EMAIL = 'Parsifal Team <noreply@parsif.al>'
EMAIL_SUBJECT_PREFIX = '[Parsifal] '
SERVER_EMAIL = 'application@parsif.al'
MENDELEY_ID = config('MENDELEY_ID', cast=int)
MENDELEY_SECRET = config('MENDELEY_SECRET')
MENDELEY_REDIRECT_URI = config('MENDELEY_REDIRECT_URI')
MENDELEY = Mendeley(MENDELEY_ID, client_secret=MENDELEY_SECRET, redirect_uri=MENDELEY_REDIRECT_URI)
DROPBOX_APP_KEY = config('DROPBOX_APP_KEY')
DROPBOX_SECRET = config('DROPBOX_SECRET')
DROPBOX_REDIRECT_URI = config('DROPBOX_REDIRECT_URI')
ELSEVIER_API_KEY = config('ELSEVIER_API_KEY')
ABSOLUTE_URL_OVERRIDES = {
'auth.user': lambda u: '/%s/' % u.username,
}
答案 0 :(得分:0)
在您的.env或.ini文件中,您需要定义DATABASE_URL:
DATABASE_URL=mysql://myuser:mypassword@myhost/mydatabase
在settings.py中更改为以下内容:
from dj_database_url import parse as db_url
DATABASES = {
'default': config('DATABASE_URL', cast=db_url),
}