Reputation: 15
This is my views.py
:
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})
This is my 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'),
)
When I am running this code, I am getting the error as :
Upvotes: 0
Views: 163
Reputation: 47374
As stacktrace said you are trying to open http://127.0.0.1/music/id/1
page not http://127.0.0.1/music/1
but there is no such urp pattern in your urls.py
. You need try to open http://127.0.0.1/music/1
or add new pattern:
url(r'^id/(?P<album_id>[0-9]+)/$', views.detail, name='detail')
to see http://127.0.0.1/music/id/1
page.
Upvotes: 1