0
這是我views.py
:URL錯誤,找不到網頁404
from django.http import Http404
from django.shortcuts import render
from .models import Album
def index(request):
all_albums = Album.objects.all()
return render(request, 'music/index.html', {'all_albums': all_albums})
def detail(request, album_id):
try:
album = Album.objects.get(pk=album_id)
except Album.DoesNotExist:
raise Http404("Album does not exist")
return render(request, '/music/detail.html', {'album': album})
這是我music\urls.py
:
from django.conf.urls import url
from . import views
urlpatterns = (
url(r'^$', views.index, name='index'),
url(r'^(?P<album_id>[0-9]+)/$', views.detail, name='detail'),
)
當我運行這段代碼,我得到的錯誤爲:
您在瀏覽器中輸入了哪個網址? –
也添加項目的'urls.py'。 – neverwalkaloner
從django.conf.urls導入包括,URL 從django.contrib中導入管理 urlpatterns的= [ URL(R '^管理員/',admin.site.urls) URL(R '^音樂/',包括('music.urls')), ] 這是項目urls –