を実行してherokuWebアプリをコンパイルしようとするとpython manage.py runserver
、次のエラーが発生します。
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',
]
プロファイルは、URLをDjangoに表示するために必要なviews.pyファイルをホストするプロジェクトディレクトリ内のフォルダです。インポートステートメントを変更して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
起こっているのかについて何か考えはありますか?
この問題は、@ dirkgrotenが正しく指摘しているように、Herokuディレクトリの構造が正しくないという結果になりました。このリポジトリhttps://github.com/heroku/heroku-django-templateで説明されている構造を使用してディレクトリを整理しました。これにより、問題が解決しました。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加