{% 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.
CodePudding user response:
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>
CodePudding user response:
If you want to show without the '', you will need to show this as an element of the list.
a = ['1','2']
So you will need to do like
<h1>
{{a[0]}}
</h1>
Or you can do something like below. It is not the best way but this does work to remove the ''. From the list, the code is:
Check the above link. You can get the code from there.
With best regards, Ranuga