My Hackpact entries here: Difference between revisions
Line 17: | Line 17: | ||
print(images_list) | print(images_list) | ||
</source> | |||
output is: | |||
<source lang="html4strict"> | |||
<img class="image" id=images_1></img> | |||
<img class="image" id=images_2></img> | |||
<img class="image" id=images_3></img> | |||
<img class="image" id=images_4></img> | |||
<img class="image" id=images_5></img> | |||
<img class="image" id=images_6></img> | |||
<img class="image" id=images_7></img> | |||
</source> | </source> | ||
==26 09 2019== | ==26 09 2019== |
Revision as of 20:20, 25 September 2019
25 09 2019
try to use Jinja to generate repetitive tags and id in html page.
from jinja2 import Template
images_html=Template('''<img>
{% for image in images %}
<img class="image" id=images_{{ image }}></img>
{% endfor %}
''')
names = ["1", "2", "3", "4", "5", "6", "7"]
images_list=images_html.render(images=names)
print(images_list)
output is:
<img class="image" id=images_1></img>
<img class="image" id=images_2></img>
<img class="image" id=images_3></img>
<img class="image" id=images_4></img>
<img class="image" id=images_5></img>
<img class="image" id=images_6></img>
<img class="image" id=images_7></img>