Issue
I have a Flask app and I am using a for loop to generate html dynamically:
{% for subcategory in subcategories|unique: %}
List of projects:
<p> {{ subcategory }}</p>
{% endfor %}
{% for subcategory in subcategories|unique: %}
List of subcategories:
<p> {{ subcategory }}</p>
{% endfor %}
However, the second for loop does not produce anything.
If I delete the "|unique" then it works.
Why?
Solution
You may be passing in a generator as opposed to a list or other iterable object.
An example generator might be:
subcategories = [str(item) for item in subcategories]
On the Python end, try wrapping the item in a list before sending it over to the Jinja renderer:
subcategories = list([str(item) for item in subcategories])
Answered By - Daniel Bond
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.