[Django]-TypeError Django

5👍

In your pattern, the parameter is called pk for the detail view:

# /music/<album_id>/
url(r'^(?P<pk>[0-9]+)/$', views.detail, name = 'detail'),
           ^^ - this is the name of the parameter that it is looking for

However, your detail view has album_id:

                    vvvvvvvv - this is not matching pk
def detail(request, album_id):
    album = get_object_or_404(Album, pk=album_id)
    return render(request, 'music/detail.html', {'album':album})

Since those two don’t match, you get the error because django cannot find a method that matches the url pattern. To fix it, make sure your pattern matches the method definition.

Leave a comment