python render html

Solutions on MaxInterview for python render html by the best coders in the world

showing results for - "python render html"
Alonso
06 Feb 2019
1# https://programminghistorian.org/en/lessons/output-data-as-html-file
2# Given name of calling program, a url and a string to wrap,
3# output string in html body with basic metadata and open in Firefox tab.
4
5def wrapStringInHTMLMac(program, url, body):
6    import datetime
7    from webbrowser import open_new_tab
8
9    now = datetime.datetime.today().strftime("%Y%m%d-%H%M%S")
10    filename = program + '.html'
11    f = open(filename,'w')
12
13    wrapper = """<html>
14    <head>
15    <title>%s output - %s</title>
16    </head>
17    <body><p>URL: <a href=\"%s\">%s</a></p><p>%s</p></body>
18    </html>"""
19
20    whole = wrapper % (program, now, url, url, body)
21    f.write(whole)
22    f.close()
23
24    #Change the filepath variable below to match the location of your directory
25    filename = 'file:///Users/username/Desktop/programming-historian/' + filename
26
27    open_new_tab(filename)