skip to navigation
skip to content

yattag 0.8.4

Library for generating HTML or XML in a pythonic way. Can fill HTML forms with default values and errors. Pure python alternative to html templating languages.

Latest Version: 1.10.0

Some examples:

( full tutorial on )

Basic example

Nested html tags, no need to close tags.

from yattag import Doc

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

with tag('html'):
    with tag('body', id = 'hello'):
        with tag('h1'):
            text('Hello world!')


Html form rendering example with default values

from yattag import Doc

doc, tag, text = Doc(
    defaults = {'ingredient': ['chocolate', 'coffee']}

with tag('form', action = ""):
    with tag('label'):
        text("Select one or more ingredients")
    with = 'ingredient', multiple = "multiple"):
        for value, description in (
            ("chocolate", "Dark chocolate"),
            ("almonds", "Roasted almonds"),
            ("honey", "Acacia honey"),
            ("coffee", "Ethiopian coffee")
            with doc.option(value = value):
    doc.stag('input', type = "submit", value = "Validate")


Full tutorial on

File Type Py Version Uploaded on Size
yattag-0.8.4.tar.gz (md5) Source 2014-04-07 6KB (md5) Source 2014-04-07 8KB