尝试通过运行python manage.py runserver
编译heroku网络应用时,出现以下错误:
Unhandled exception in thread started by <function wrapper at 0x1046deb18>
Traceback (most recent call last):
File "/Users/User/Desktop/App/App/lib/python2.7/site-packages/django/utils/autoreload.py", line 228, in wrapper
fn(*args, **kwargs)
File "/Users/User/Desktop/App/App/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 117, in inner_run
autoreload.raise_last_exception()
File "/Users/User/Desktop/App/App/lib/python2.7/site-packages/django/utils/autoreload.py", line 251, in raise_last_exception
six.reraise(*_exception)
File "/Users/User/Desktop/App/App/lib/python2.7/site-packages/django/utils/autoreload.py", line 228, in wrapper
fn(*args, **kwargs)
File "/Users/User/Desktop/App/App/lib/python2.7/site-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/User/Desktop/App/App/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/Users/User/Desktop/App/App/lib/python2.7/site-packages/django/apps/config.py", line 94, in create
module = import_module(entry)
File "/usr/local/Cellar/python/2.7.14/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named profiles
主要问题是No module named profiles
。配置文件在app.py中定义:
from __future__ import unicode_literals
from django.apps import AppConfig
class ProfilesConfig(AppConfig):
name = 'profiles'
并在urls.py中调用
from django.conf import settings
from django.conf.urls.static import static
from django.conf.urls import url
from django.contrib import admin
from profiles import views
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^$', views.home, name='home'),
url(r'^one/', views.one, name='one'),
url(r'^two/', views.two, name='two'),
url(r'^three/', views.three, name='three'),
url(r'^four/', views.four, name='four'),
url(r'^five/', views.five, name='five'),
]
还在settings.py
中添加了个人资料INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
# Disable Django's own staticfiles handling in favour of WhiteNoise, for
# greater consistency between gunicorn and `./manage.py runserver`. See:
# http://whitenoise.evans.io/en/stable/django.html#using-whitenoise-in-development
'whitenoise.runserver_nostatic',
'django.contrib.staticfiles',
'profiles',
]
配置文件是我项目目录中的一个文件夹,它托管了我的网址在Django中显示所需的views.py文件。我尝试修改import语句,摆弄settings.py,但没有任何工作,这就是显示的错误。
项目结构:
|—App
|—App
|—__init__.py
|—__init__.pyc
|—bin
|— include
|—lib
|—profiles
|—__init__.py
|—__init__.pyc
|— admin.py
|— admin.pyc
|— apps.py
|— models.pyc
|— templates
|— tests.py
|— views.py
|— views.pyc
|—static
|—staticfiles
|— urls.py
|— urls.pyc
|—wsgi.py
|—wsgi.pyc
|—db.sqlite3
|—manage.py
|—Procfile
|—requirements.txt
|—runtime.txt
有关为什么ImportError: No module named profiles
发生的任何想法?
答案 0 :(得分:0)
正如@dirkgroten正确指出的那样,问题最终是我的Heroku目录的结构不正确。我使用此repo https://github.com/heroku/heroku-django-template中描述的结构组织了目录,并解决了这些问题。