【发布时间】:2020-11-22 01:27:09
【问题描述】:
当我尝试访问我的 Heroku 应用程序时,我不断收到“ModuleNotFoundError at /”错误。当我在localhost:8000 上运行它时它工作正常。
我的项目目录如下所示:
首页
-pycache(文件夹)
-迁移(文件夹)
-模板(文件夹)
-__init.py__
-admin.py
-apps.py
-forms.py
-models.py
-tests.py
-urls.py
-views.py
日志错误:
ModuleNotFoundError at /
No module named 'frontpage.forms'
Request Method: GET
Request URL: http://cottonthebutton.herokuapp.com/
Django Version: 3.0.8
Exception Type: ModuleNotFoundError
Exception Value:
No module named 'frontpage.forms'
Exception Location: /app/frontpage/views.py in <module>, line 5
Python Executable: /app/.heroku/python/bin/python
Python Version: 3.8.5
Python Path:
['/app/.heroku/python/bin',
'/app',
'/app/.heroku/python/lib/python38.zip',
'/app/.heroku/python/lib/python3.8',
'/app/.heroku/python/lib/python3.8/lib-dynload',
'/app/.heroku/python/lib/python3.8/site-packages']
Server time: Sat, 1 Aug 2020 19:16:39 +0800
追溯:
Environment:
Request Method: GET
Request URL: http://cottonthebutton.herokuapp.com/
Django Version: 3.0.8
Python Version: 3.8.5
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'frontpage']
Installed Middleware:
('whitenoise.middleware.WhiteNoiseMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware')
Traceback (most recent call last):
File "/app/.heroku/python/lib/python3.8/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/app/.heroku/python/lib/python3.8/site-packages/django/core/handlers/base.py", line 100, in _get_response
resolver_match = resolver.resolve(request.path_info)
File "/app/.heroku/python/lib/python3.8/site-packages/django/urls/resolvers.py", line 544, in resolve
for pattern in self.url_patterns:
File "/app/.heroku/python/lib/python3.8/site-packages/django/utils/functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/app/.heroku/python/lib/python3.8/site-packages/django/urls/resolvers.py", line 588, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/app/.heroku/python/lib/python3.8/site-packages/django/utils/functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/app/.heroku/python/lib/python3.8/site-packages/django/urls/resolvers.py", line 581, in urlconf_module
return import_module(self.urlconf_name)
File "/app/.heroku/python/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
<source code not available>
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
<source code not available>
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
<source code not available>
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
<source code not available>
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
<source code not available>
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
<source code not available>
File "/app/PersonalWebsite/urls.py", line 21, in <module>
path('', include('frontpage.urls'))
File "/app/.heroku/python/lib/python3.8/site-packages/django/urls/conf.py", line 34, in include
urlconf_module = import_module(urlconf_module)
File "/app/.heroku/python/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
<source code not available>
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
<source code not available>
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
<source code not available>
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
<source code not available>
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
<source code not available>
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
<source code not available>
File "/app/frontpage/urls.py", line 2, in <module>
from frontpage import views
File "/app/frontpage/views.py", line 5, in <module>
from frontpage.forms import MessageForm
Exception Type: ModuleNotFoundError at /
Exception Value: No module named 'frontpage.forms'
【问题讨论】:
-
尝试使用 'frontpage.apps.FrontpageConfig' 或您拥有的任何配置文件而不是 frontpage?
-
什么配置文件?
frontpage(最上面的那个)是文件夹的名称。我认为它是项目文件夹,因为 manage.py 文件在该文件夹下。 -
您的首页应用程序中有
apps.py文件吗? -
天哪。我很抱歉。我忘了在我的 git push 中添加
forms.py。对不起!