how to generate web page with pure python

PHOTO EMBED

Wed Oct 23 2024 19:52:13 GMT+0000 (Coordinated Universal Time)

Saved by @freepythoncode ##python #coding #python #programming

from yattag import Doc

import webbrowser

doc, tag, text = Doc().tagtext()

doc.asis('<!DOCTYPE html>')

with tag('html') as html:
    with tag('head') as head:
        with tag('title') as title:
            text('This is test web page')
    with tag('body') as body:
        with tag('h2') as h2:
            text('This is h2')

page = doc.getvalue()

f = open('page.html', 'w')
f.write(page)
f.close()

webbrowser.open('page.html')
content_copyCOPY