그래서 데이터베이스의 특정 아티스트가 발표 한 제목과 노래 및 앨범을 표시하는 프로젝트를 진행하고 있습니다. 나는 좀 붙어있다. 앨범 링크를 클릭하면 앨범에있는 노래를 표시하는 페이지를 만들려고합니다. 링크를 클릭하면 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 (앨범, 제목 = 앨범)입니다. – Zartch
@Zartch 어떻게 수정합니까? – HackAfro