2016-04-17 18 views
0

どこからエラーが発生しているのか分かりませんが、これは私が見逃した最後のファイルです。私は、ImportError:No moduleという名前の 'index'を取得します。ImportError: 'index'という名前のモジュールがありません

from django.conf.urls import url 

from . import views 

from .models import Album 


urlpatterns = [ 
    #/index.html/ 
    url(r'^$', views.index ,name='index'), 
    #/index.html/71/ 
    url(r'^(?P<album_id>[0-9]+)/$', views.details, name='detail') 
] 

________________________________ビュー__________________________________

from django.shortcuts import render 
from django.http import HttpResponse 
from .models import Album 
from django.template import loader 

# Create your views here. 

def index(request): 
    all_albums = Album.objects.all() 
    template = loader.get_template('/music/index.html') 
    context = { 
     'all_albums': all_albums, 
    } 
    return HttpResponse(template.render(context,request)) 

def details(request, album_id): 
    return HttpResponse("<h2> details for album id: " + str(album_id) + "</h2>") 

-----------------------------トレースバック - -------------------------------

Tyrees-MacBook-Pro:tyree_website tyreestevenson$ python3 manage.py runserver 
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x103b7eb70> 
Traceback (most recent call last): 
    File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/utils/autoreload.py", line 226, in wrapper 
    fn(*args, **kwargs) 
    File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/core/management/commands/runserver.py", line 109, in inner_run 
    autoreload.raise_last_exception() 
    File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/utils/autoreload.py", line 249, in raise_last_exception 
    six.reraise(*_exception) 
    File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/utils/six.py", line 685, in reraise 
    raise value.with_traceback(tb) 
    File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/utils/autoreload.py", line 226, in wrapper 
    fn(*args, **kwargs) 
    File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/__init__.py", line 18, in setup 
    apps.populate(settings.INSTALLED_APPS) 
    File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/apps/registry.py", line 85, in populate 
    app_config = AppConfig.create(entry) 
    File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/apps/config.py", line 116, in create 
    mod = import_module(mod_path) 
    File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/importlib/__init__.py", line 126, in import_module 
    return _bootstrap._gcd_import(name[level:], package, level) 
    File "<frozen importlib._bootstrap>", line 986, in _gcd_import 
    File "<frozen importlib._bootstrap>", line 969, in _find_and_load 
    File "<frozen importlib._bootstrap>", line 944, in _find_and_load_unlocked 
    File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed 
    File "<frozen importlib._bootstrap>", line 986, in _gcd_import 
    File "<frozen importlib._bootstrap>", line 969, in _find_and_load 
    File "<frozen importlib._bootstrap>", line 944, in _find_and_load_unlocked 
    File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed 
    File "<frozen importlib._bootstrap>", line 986, in _gcd_import 
    File "<frozen importlib._bootstrap>", line 969, in _find_and_load 
    File "<frozen importlib._bootstrap>", line 956, in _find_and_load_unlocked 
ImportError: No module named 'index' 
+0

完全なトレースバックを表示できますか? – mgilson

+0

トレースバック@mgilsonを追加しました – user3697597

+0

エラーが設定に関連しているようです。そこには 'index'があります。 –

答えて

0

なぜこのエラーが発生するのかわかりません。

url(r'^$', views.index ,name='index'),をコメントアウトするとどうなりますか?

patternsショートカット(および相対インポートなし)で試したことがありますか?例:

from django.conf.urls import patterns, include, url 

urlpatterns += patterns('your_app.views', 
    #/index.html/ 
    url(r'^$', 'index' ,name='index'), 
    #/index.html/71/ 
    url(r'^(?P<album_id>[0-9]+)/$', 'details', name='detail') 
) 
+1

これはもう解決しません。https://docs.djangoproject.com/en/1.9/intro/tutorial01/ – Wtower

関連する問題