Home Django- template loop but exclude repeats
Reply: 0

Django- template loop but exclude repeats

user746 Published in March 22, 2018, 9:19 pm

Say I have this data and I'm passing to my template:

apps = [
 {'category': 'one', 'item': 'blah'},
 {'category': 'one', 'item': 'blah'},
 {'category': 'two', 'item': 'blah'},
 {'category': 'two', 'item': 'blah'},
 {'category': 'three', 'item': 'blah'}

Then in my template I want to add one div withe the id 'category' but not repeat any divs if they've been added before with the id. So something similar to:

{% for app in apps %}
   <div id="{{app.category}}"></div>
{% endfor %}

But I only want these to be rendered:

<div id="one"></div>
<div id="two"></div>
<div id="three"></div>
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.322591 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO