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"),
- [Django]-Passing STATIC_URL to file javascript with django
- [Django]-Serializer call is showing an TypeError: Object of type 'ListSerializer' is not JSON serializable?
- [Django]-Django character set with MySQL weirdness
Source:stackexchange.com