0π
β
In your view:
titles = ('Hello', 'Umbrella')
artists = ('Adele', 'Rihanna')
songs = {'titles_artists': zip(titles, artist)}
in your template:
{% for title, artist in titles_artists %}
<p>{{ title }}<br>{{ artist }}</p>
{% endfor %}
You can try rethink your context dictionary, something like:
songs = {'artists': [
{'name': 'Adele', 'titles': ['Hello', ]},
{'name': 'Rihanna', 'titles': ['Umbrella', ]}
]
}
And in your template:
{% for artist in artists %}
{% for title in artist.titles %}
{{ title }}
{% endfor %}
{{ artist.name }}
{% endfor %}
π€Anderson Lima
1π
Do this:
for title, artist in zip(songs['titles'], songs['artists']):
print(title)
print(artist)
print() # In Python 2, remove the parentheses
π€zondo
- How do i import list of variables as choices for a charfield from outside the app?
- Every time I launch a new project this error pops up about installing django packages
Source:stackexchange.com