我有一个Django应用程序,我从Github repo下载的,主应用程序不叫“mywebsite”(就像Django教程中所指示的那样)。
每次运行python manage.py runserver
时,我都会得到以下错误。
从概念上讲我理解这个错误,但实际上我不理解。问题不可能是我总是需要将我的repo命名为“mywebsite”,对吗?
这是当前的回购结构。
Traceback (most recent call last):
File "/Users/nicolamacchitella/Documents/GitHub/familytree/.env/lib/python3.9/site-packages/django/core/management/base.py", line 402, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/nicolamacchitella/Documents/GitHub/familytree/.env/lib/python3.9/site-packages/django/core/management/commands/runserver.py", line 74, in execute
super().execute(*args, **options)
File "/Users/nicolamacchitella/Documents/GitHub/familytree/.env/lib/python3.9/site-packages/django/core/management/base.py", line 448, in execute
output = self.handle(*args, **options)
File "/Users/nicolamacchitella/Documents/GitHub/familytree/.env/lib/python3.9/site-packages/django/core/management/commands/runserver.py", line 81, in handle
if not settings.DEBUG and not settings.ALLOWED_HOSTS:
File "/Users/nicolamacchitella/Documents/GitHub/familytree/.env/lib/python3.9/site-packages/django/conf/__init__.py", line 92, in __getattr__
self._setup(name)
File "/Users/nicolamacchitella/Documents/GitHub/familytree/.env/lib/python3.9/site-packages/django/conf/__init__.py", line 79, in _setup
self._wrapped = Settings(settings_module)
File "/Users/nicolamacchitella/Documents/GitHub/familytree/.env/lib/python3.9/site-packages/django/conf/__init__.py", line 190, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/opt/homebrew/Cellar/python@3.9/3.9.7_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 972, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'mywebsite'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/nicolamacchitella/Documents/GitHub/familytree/Yggdrasil/yggdrasil/manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/Users/nicolamacchitella/Documents/GitHub/familytree/.env/lib/python3.9/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
utility.execute()
File "/Users/nicolamacchitella/Documents/GitHub/familytree/.env/lib/python3.9/site-packages/django/core/management/__init__.py", line 440, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/nicolamacchitella/Documents/GitHub/familytree/.env/lib/python3.9/site-packages/django/core/management/base.py", line 415, in run_from_argv
connections.close_all()
File "/Users/nicolamacchitella/Documents/GitHub/familytree/.env/lib/python3.9/site-packages/django/utils/connection.py", line 84, in close_all
for conn in self.all(initialized_only=True):
File "/Users/nicolamacchitella/Documents/GitHub/familytree/.env/lib/python3.9/site-packages/django/utils/connection.py", line 76, in all
return [
File "/Users/nicolamacchitella/Documents/GitHub/familytree/.env/lib/python3.9/site-packages/django/utils/connection.py", line 73, in __iter__
return iter(self.settings)
File "/Users/nicolamacchitella/Documents/GitHub/familytree/.env/lib/python3.9/site-packages/django/utils/functional.py", line 57, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/Users/nicolamacchitella/Documents/GitHub/familytree/.env/lib/python3.9/site-packages/django/utils/connection.py", line 45, in settings
self._settings = self.configure_settings(self._settings)
File "/Users/nicolamacchitella/Documents/GitHub/familytree/.env/lib/python3.9/site-packages/django/db/utils.py", line 148, in configure_settings
databases = super().configure_settings(databases)
File "/Users/nicolamacchitella/Documents/GitHub/familytree/.env/lib/python3.9/site-packages/django/utils/connection.py", line 50, in configure_settings
settings = getattr(django_settings, self.settings_name)
File "/Users/nicolamacchitella/Documents/GitHub/familytree/.env/lib/python3.9/site-packages/django/conf/__init__.py", line 92, in __getattr__
self._setup(name)
File "/Users/nicolamacchitella/Documents/GitHub/familytree/.env/lib/python3.9/site-packages/django/conf/__init__.py", line 79, in _setup
self._wrapped = Settings(settings_module)
File "/Users/nicolamacchitella/Documents/GitHub/familytree/.env/lib/python3.9/site-packages/django/conf/__init__.py", line 190, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/opt/homebrew/Cellar/python@3.9/3.9.7_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 972, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'mywebsite'
2条答案
按热度按时间nr9pn0ug1#
很可能是因为您的项目名称。目前您有两个选项:(1)重命名回mywebsite或(2)将项目中所有出现的“mywebsite”重命名为您的项目名称。
如果你选择(2),检查你的项目设置,你会看到很多像
ROOT_URLCONF = 'mywebsite.urls'
这样的变量,你必须将其更改为ROOT_URLCONF = 'yggdrasil.urls'
。你也必须在你所有的应用和其他任何使用mywebsite
作为根引用的地方这样做。bvjxkvbb2#
我已经检查了回购协议中的代码,显然一切都很正常。
再看看OP得到的错误,它从行开始
然后使用与Windows不同的路径搜索文件,File“/opt/homebrew/Cellar/python....这表明OP在导入设置模块时遇到问题。
经过一番挖掘,在Django文档中找到了这一页
如果没有设置这个变量,默认的wsgi.py会将其设置为mysite.settings,其中mysite是你的项目名称,这就是runserver在默认情况下发现默认设置文件的方式。
要解决此问题,请尝试在wsgi.py file中强制执行的值,例如