Search code examples
pythonhtmlpathpathlib

How can i insert multiple images, in html tag using Python html


i want to write multiple html file that contains multiple images at once but in the outputs files shows the last image in the list of images only

path = pathlib.Path('./'+str(f))

images = ['1.png','2.png','3.png'....]
    
for image in images:

     with open(str(f)+".html","w") as file:
            
          file.write('''<div class="card"><img src="'''+image+'''" alt=" "/>''')

Solution

  • You'r code should be:

    with open(str(f)+".html","w") as file:
        for image in images:
              file.write('''<div class="card"><img src="'''+image+'''" alt=" "/>''')