我目前正在尝试从默认的Django结构更改为该结构。
我现在复制了新文件夹中的所有文件,但是运行python manage.py runserver --settings=settings.local
时,它将在我的终端上显示以下内容:
Traceback (most recent call last):
File "manage.py", line 16, in <module>
execute_from_command_line(sys.argv)
File "/Users/Marc/.local/share/virtualenvs/lumis-vJ5Odiz7/lib/python3.6/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
utility.execute()
File "/Users/Marc/.local/share/virtualenvs/lumis-vJ5Odiz7/lib/python3.6/site-packages/django/core/management/__init__.py", line 317, in execute
settings.INSTALLED_APPS
File "/Users/Marc/.local/share/virtualenvs/lumis-vJ5Odiz7/lib/python3.6/site-packages/django/conf/__init__.py", line 56, in __getattr__
self._setup(name)
File "/Users/Marc/.local/share/virtualenvs/lumis-vJ5Odiz7/lib/python3.6/site-packages/django/conf/__init__.py", line 43, in _setup
self._wrapped = Settings(settings_module)
File "/Users/Marc/.local/share/virtualenvs/lumis-vJ5Odiz7/lib/python3.6/site-packages/django/conf/__init__.py", line 106, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/Users/Marc/.local/share/virtualenvs/lumis-vJ5Odiz7/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'settings'
有人可以看到我在做什么错吗? 我还将wsgi.py和manage.py更改为以下内容:
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")
答案 0 :(得分:0)
您需要通过创建空白的config/
文件将config/__init__.py
目录转换为python模块,然后在DJANGO_SETTINGS_MODULE
和{{1}中像这样配置manage.py
}:
config/wsgi.py
然后,您应该可以只运行os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.local")
而无需使用./manage.py runserver
选项。
答案 1 :(得分:0)
您需要告诉django在哪里寻找设置模块,因此必须在manage.py
中指定模块路径:
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")
并在设置文件夹内的__init__.py
中添加以下行:
try:
from config.settings.local import *
except:
pass
答案 2 :(得分:0)