from yattag import Doc doc, tag, text = Doc().tagtext() with tag('html'): with tag('head'): with tag('title'): text('My HTML Page') with tag('body'): with tag('h1'): text('Welcome to my page!') # prints out the resulting HTML print(doc.getvalue())
from yattag import Doc doc, tag, text = Doc().tagtext() with tag('html', xmlns='http://www.w3.org/1999/xhtml'): with tag('head'): with tag('title'): text('My XHTML Page') with tag('body'): with tag('h1'): text('My List') with tag('ul'): with tag('li'): text('Item 1') with tag('li'): text('Item 2') # prints out the resulting XHTML print(doc.getvalue())In both examples, yattag's Doc tag is used to create a document structure and then nested tags are used to add content to the document. The resulting HTML or XHTML is created by calling `doc.getvalue()`.