I have this urlpatterns..
urlpatterns = [
path('', views.index, name='index'),
path('<int:album_id>/', views.detail, name='detail'),
]
my index.html looks like this
<h1>Albums to display</h1>
<ul>
{% for album in all_albums %}
<li><a href="/music/{{ album_id }}/"> {{ album.album_title }}</a></li>
{% endfor %}
</ul>
#my index.html simply displays my albums. and the above works just fine
my detail.html looks like this
{{ album }}
#and it works just fine too
my views.py looks like this
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})
#when ever I click on an album link to get the album details, I get the 404 below:
Page not found (404)
Request Method: GET
Using the URLconf defined in website.urls, Django tried these URL patterns, in this order:
1. admin/
2. music/ [name='index']
3. music/ <int:album_id>/ [name='detail']
The current path, music//, didn't match any of these.
in my detail funtion in views.py, at first I used on request as an argument and it worked just fine to give me the album details (which returned only the album id number), but when i added album_id, so as to get the album details, I got an error. saying music// not found. Now I don't understand how the last forward slash(/) was added.
can I get the explaination to this. Thanks