Skip to content

Instantly share code, notes, and snippets.

@israel-dryer
Created September 16, 2020 14:50
Show Gist options
  • Save israel-dryer/036f0118ebe0a9e4548873c10794dade to your computer and use it in GitHub Desktop.
Save israel-dryer/036f0118ebe0a9e4548873c10794dade to your computer and use it in GitHub Desktop.
Insert python list into html formatted email template
"""
Create a html formatted list from a python list
"""
# email template with curly braces to insert list
email_template = '''
<p>Hello, here are the items that you ordered:<br>
{}
</p>
'''
# the list of products the customer ordered
products = ['Radio', 'Computer', 'Monitor']
# build an html formatted list from the python list
html_list = "<ul>"
for prod in products:
html_list += f"<li>{prod}</li>"
html_list += "</ul>"
html_body = email_template.format(html_list)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment