开发者

Django template question?

开发者 https://www.devze.com 2023-03-15 01:26 出处:网络
I need to display all the videos within a certain playlist. I can display all the avaliable playlists by using开发者_开发技巧 this loop:

I need to display all the videos within a certain playlist. I can display all the avaliable playlists by using开发者_开发技巧 this loop:

{% for p in playlists %}

    {{ p.playlist.name }}

{% endfor %}

How can I display all the videos in each playlist too?


It's hard to say since you don't show your models, but something like this could work:

<ul>
{% for p in playlists %}

<li>{{ p.playlist.name }}
    <ul>
    {% for v in p.playlist.videos %}
    <li>{{ v.name }}</li>
    {% endfor %}
    </ul>
</li>
{% endfor %}
</ul>

I'm assuming your videos have a ForeignKey(Playlist, related_name="videos") field.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号