私は、データベースの特定のアーティストによってリリースされたタイトルと曲とアルバムを表示するプロジェクトに取り組んでいます。私はちょっと固まっている。私はアルバムリンクをクリックするとアルバム内の曲を表示するページを作成しようとしています。リンクをクリックすると、URLにアーティスト名とアルバムタイトルが表示されますが、同じエラーが表示され続けます。これは、アーティスト名とアルバムの名前を一致させています。DjangoのURL confに関する問題
ページにアルバムの曲を表示するにはどうすればよいですか。
は、ここでビューのコードです
def home(request):
artistes = Artiste.objects.all()
return render(request, 'music/home.html', locals())
def details(request, artiste):
artistes = get_object_or_404(Artiste, name=artiste)
album = Artiste.objects.get(name=artiste).album_set.all()
single = Artiste.objects.get(name=artiste).song_set.filter(single=True)
return render(request, 'music/details.html', {'artistes': artistes, 'single': single, 'album':album})
def album_details(request,name,album):
albums = get_object_or_404(Album, title=album)
artistes = get_object_or_404(Artiste, name=name)
single = Album.objects.get(title=album).song_set.filter(single=False)
return render(request, 'music/album_detail.html', {'albums': albums, 'single': single})
URLパターン
app_name = 'music'
urlpatterns = [
url(r'^$', views.home, name='home'),
url(r'^(?P<artiste>.+)/$', views.details, name='details'),
url(r'^(?P<name>.+)/(?P<album>.+)/$', views.album_details, name='album_details')
]
アルバムの詳細ページ
<body>
{% if artistes.album_set.all %}
{% for songs in album %}
<h4>Albums</h4>
<!--<img src="{{album.art}}"><br>
-->
<a href="{% url 'music:album_details' songs.artiste songs.title %}">{{songs.title}}</a>
<h5>{{songs.artiste}}</h5>
<h5>{{songs.title}}</h5>
{% endfor %}
{% else %}
<h3>No albums available</h3>
<h5>Check Out Songs </h5>
<ul>
{% for song in artistes.song_set.all %}
<li>{{song}} - mp3</li>
{% endfor %}
</ul>
{% endif %}
</body>
</html>
エラーは、URLにないalbums = get_object_or_404(Album、title = album)です。 – Zartch
@Zartchどうすれば修正できますか? – HackAfro