My Hackpact entries here: Difference between revisions

From XPUB & Lens-Based wiki
Line 5: Line 5:
from jinja2 import Template
from jinja2 import Template


images_html=Template('''<img>
images_html=Template('''
{% for image in images %}
{% for image in images %}
<img class="image" id=images_{{ image }}></img>
<img class="gallery" href="{{ image }}.jpg" id=images_{{ image }}></img>
{% endfor %}
{% endfor %}
 
''')
''')


names = ["1", "2", "3", "4", "5", "6", "7"]
numberList = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]


images_list=images_html.render(images=names)
images_list=images_html.render(images=numberList)
print(images_list)
print(images_list)


</source>
</source>


output is:
output is:
        <source lang="html4strict">
<source lang="html4strict">
         <img class="image" id=images_1></img>
         <img class="gallery" href="1.jpg" id=images_1></img>
<img class="gallery" href="2.jpg" id=images_2></img>
<img class="gallery" href="3.jpg" id=images_3></img>
<img class="gallery" href="4.jpg" id=images_4></img>
<img class="image" id=images_2></img>
<img class="gallery" href="5.jpg" id=images_5></img>
<img class="image" id=images_3></img>
<img class="gallery" href="6.jpg" id=images_6></img>
<img class="image" id=images_4></img>
<img class="gallery" href="7.jpg" id=images_7></img>
<img class="image" id=images_5></img>
<img class="gallery" href="8.jpg" id=images_8></img>
<img class="image" id=images_6></img>
<img class="gallery" href="9.jpg" id=images_9></img>
<img class="image" id=images_7></img>
<img class="gallery" href="10.jpg" id=images_10></img>


</source>
</source>


==26 09 2019==
==26 09 2019==

Revision as of 20:46, 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('''
	{% for image in images %}
	<img class="gallery" href="{{ image }}.jpg" id=images_{{ image }}></img>
	{% endfor %}

''')

numberList = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]

images_list=images_html.render(images=numberList)
print(images_list)

output is:

        <img class="gallery" href="1.jpg" id=images_1></img>
	
	<img class="gallery" href="2.jpg" id=images_2></img>
	
	<img class="gallery" href="3.jpg" id=images_3></img>
	
	<img class="gallery" href="4.jpg" id=images_4></img>
	
	<img class="gallery" href="5.jpg" id=images_5></img>
	
	<img class="gallery" href="6.jpg" id=images_6></img>
	
	<img class="gallery" href="7.jpg" id=images_7></img>
	
	<img class="gallery" href="8.jpg" id=images_8></img>
	
	<img class="gallery" href="9.jpg" id=images_9></img>
	
	<img class="gallery" href="10.jpg" id=images_10></img>

26 09 2019