[Django]-Django – getting Error "Reverse for 'detail' with no arguments not found. 1 pattern(s) tried:" when using {% url "music:fav" %}

42👍

path("<album_id>/fav/", views.fav, name="fav"),

This URL needs the album_id. Something like this:

{% url 'music:fav' 1 %}
{% url 'music:fav' album.id %}

6👍

The reason is because your view needs an album_id argument

music/views.py

def fav(request, album_id):
    # then filter by album id instead of a default value of 1
    song = Song.objects.get(id=album_id)
    song.is_favorite = True
    return render(request, "detail.html")

the trick here is that your url expects to match

views.py

def fav(request, album_id):

urls

path("<int:album_id>/fav/", views.fav, name="fav"),

Leave a comment