If you want to try this "better" way of managing files, you can set it up in seconds:

images = [f for f in os.listdir('.') if f.endswith(('.jpg','.png'))] with open('index.html', 'w') as f: f.write(Template(html_template).render(images=images))

Choose the method that fits your technical comfort and use case. But never settle for the raw, ugly default. Your photos—and your sanity—deserve a .