我试图让Django工作。我安装了Django
django-admin startproject mysite
这创建了这个结构
mysite
-- manage.py
-- mysite
- __init__.py
- settings.py
- etc etc...
现在我在跑步时
python manage.py runserver
我收到此错误
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "C:\MySoftware\python361\lib\site-packages\django\core\management\__init__.py", line 363, in execute_from_command_line
utility.execute()
File "C:\MySoftware\python361\lib\site-packages\django\core\management\__init__.py", line 307, in execute
settings.INSTALLED_APPS
File "C:\MySoftware\python361\lib\site-packages\django\conf\__init__.py", line 56, in __getattr__
self._setup(name)
File "C:\MySoftware\python361\lib\site-packages\django\conf\__init__.py", line 41, in _setup
self._wrapped = Settings(settings_module)
File "C:\MySoftware\python361\lib\site-packages\django\conf\__init__.py", line 110, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "importlib\__init__.py", line 126, in import_module
File "<frozen importlib._bootstrap>", line 978, in _gcd_import
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
File "<frozen importlib._bootstrap>", line 936, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 978, in _gcd_import
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
File "<frozen importlib._bootstrap>", line 948, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'mysite'
Python无法找到&#39; mysite&#39; 我已经尝试过PYTHONPATH =&#39;我的导演&#39;但到目前为止还没有任何效果。问题似乎是python找不到mysite文件夹
答案 0 :(得分:0)
好的,我正在回答我自己的问题。
由于一些奇怪的原因,Python无法找到app文件夹/ mysite,即使我设置了
PYTHONPATH = C:\...\mysite
它不起作用
我找到了一个黑客,通过在
之后插入目录来包含目录import sys
sys.path.append("C:\\xampp\\your\\path\\site1") <--- insert this line (3)
在manage.py中,这会强制python在运行服务器时查找你的app文件夹。也放双斜杠。