我正在尝试为django项目运行一个简单的测试,并将它们分成两个文件,因为这是一个很好的做法,但是,这总是给我一个错误
ImproperlyConfigured("settings.DATABASES is improperly configured. "
我不知道为什么我最终在我的settings.py
try:
from local_settings import *
except:
pass
并且仅在local_settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
并且是的,在同一目录中。我正在使用python3,windows 10
追踪错误
Traceback (most recent call last):
File "C:\Users\Kevin\Documents\prueba\prueba\manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\Kevin\Documents\prueba\venv\lib\site-packages\django\core\management\__init__.py", line 363, in execute_from_command_line
utility.execute()
File "C:\Users\Kevin\Documents\prueba\venv\lib\site-packages\django\core\management\__init__.py", line 355, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\Kevin\Documents\prueba\venv\lib\site-packages\django\core\management\base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\Kevin\Documents\prueba\venv\lib\site-packages\django\core\management\base.py", line 330, in execute
output = self.handle(*args, **options)
File "C:\Users\Kevin\Documents\prueba\venv\lib\site-packages\django\core\management\commands\migrate.py", line 83, in handle
executor = MigrationExecutor(connection, self.migration_progress_callback)
File "C:\Users\Kevin\Documents\prueba\venv\lib\site-packages\django\db\migrations\executor.py", line 20, in __init__
self.loader = MigrationLoader(self.connection)
File "C:\Users\Kevin\Documents\prueba\venv\lib\site-packages\django\db\migrations\loader.py", line 52, in __init__
self.build_graph()
File "C:\Users\Kevin\Documents\prueba\venv\lib\site-packages\django\db\migrations\loader.py", line 209, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "C:\Users\Kevin\Documents\prueba\venv\lib\site-packages\django\db\migrations\recorder.py", line 65, in applied_migrations
self.ensure_schema()
File "C:\Users\Kevin\Documents\prueba\venv\lib\site-packages\django\db\migrations\recorder.py", line 52, in ensure_schema
if self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor()):
File "C:\Users\Kevin\Documents\prueba\venv\lib\site-packages\django\db\backends\base\base.py", line 254, in cursor
return self._cursor()
File "C:\Users\Kevin\Documents\prueba\venv\lib\site-packages\django\db\backends\dummy\base.py", line 20, in complain
raise ImproperlyConfigured("settings.DATABASES is improperly configured. "
django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.
修改
修复此问题
LOCAL_SETTINGS
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'db.sqlite3',
}
}
DEBUG = True
如果将此部署到heroku
,请将其添加到设置的末尾import dj_database_url
DATABASES = {'default': dj_database_url.config()}
DEBUG = False
ALLOWED_HOSTS = ['*']
try:
from .local_settings import *
except ImportError:
pass
答案 0 :(得分:1)
在Python 3中,相对导入应该是
from .local_settings import *