photos = glob.glob('photos/*.jpg')
with document(title='Photos') as doc:
    h1('Photos')
for path in photos:
    div(img(src=path), _class='photo')
with open('gallery.html', 'w') as f:
    f.write(doc.render())
Creating HTML in python