Skip to main content

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.

Project description

Some examples:

( full tutorial on yattag.org )

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!')

print(doc.getvalue())

Html form rendering example with default values

from yattag import Doc

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

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

print(doc.getvalue())

Full tutorial on yattag.org

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

yattag-0.8.2.zip (7.3 kB view details)

Uploaded Source

yattag-0.8.2.tar.gz (5.1 kB view details)

Uploaded Source

File details

Details for the file yattag-0.8.2.zip.

File metadata

  • Download URL: yattag-0.8.2.zip
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for yattag-0.8.2.zip
Algorithm Hash digest
SHA256 499d1d5054461f9e1988fbf9731a50fb5a7e701e2a8c6c16804249d1c6661133
MD5 e859195270ba40bcc50d1625e7cf1dba
BLAKE2b-256 ee5367ddec8bac91ae81469ba0487f47284a4d8ab601b3d771fe9eae2afd6f68

See more details on using hashes here.

File details

Details for the file yattag-0.8.2.tar.gz.

File metadata

  • Download URL: yattag-0.8.2.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for yattag-0.8.2.tar.gz
Algorithm Hash digest
SHA256 f5a1777d8be9af81423a5bd3269bd4ca3a50bce66a93c34abffc8f2c0225136a
MD5 3a478223571145956a14f386991564af
BLAKE2b-256 5921eac8d5ebc4e87a59ea4117bab137214e1c18cf672137e52863d372518822

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page