Issue
{% for term in terms %}
<div class="term term-count-{{loop.index}}">
<b>{{ term }}</b>: {{ terms[term] }}
</div>
{% endfor %}
'terms' is a dictionary with the value as a list in Python:
terms = {'a':['1','2','3'], 'b':['4','5','6'], 'c': ['x', 'y', 'z']}
The current html code will display the 'terms' as follows in the for loop:
a: ['1','2','3']
b: ['4','5','6']
c: ['x', 'y', 'z']
I want the quotes to be removed as follows:
a: [1, 2, 3]
b: [4, 5, 6]
c: [x, y, z]
Is there a way to run a string removing function in the html blocks? If not, is there other possible ways to display as I expected? This is in a Flask project.
Solution
Change your html to
{% for key, value in terms.items() %}
<div class="term term-count-{{loop.index}}">
<b>{{ key }}</b>: [{{ value|join(', ') }}]
</div>
{% endfor %}
it will render to:
<div class="term term-count-1">
<b>a</b>: [1, 2, 3]
</div>
<div class="term term-count-2">
<b>b</b>: [4, 5, 6]
</div>
<div class="term term-count-3">
<b>c</b>: [x, y, z]
</div>
Answered By - buran
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.