Skip to main content

Generate HTML or XML in a pythonic way. Pure python alternative to web template engines.Can fill HTML forms with default values and error messages.

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.9.4.zip (11.2 kB view details)

Uploaded Source

yattag-0.9.4.tar.gz (8.9 kB view details)

Uploaded Source

File details

Details for the file yattag-0.9.4.zip.

File metadata

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

File hashes

Hashes for yattag-0.9.4.zip
Algorithm Hash digest
SHA256 2aa1996be9f62b96f06cc5e04e560d0de719c2f2dde28eb0d5e76c8253da220c
MD5 a361860fb9b6b358b39e07fea0c39033
BLAKE2b-256 3bbc7cf5790997cf16bfe8f371b81b27616b0a2b95575206ad6ec35f87c0f984

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for yattag-0.9.4.tar.gz
Algorithm Hash digest
SHA256 77124a88e59d9e2cd0aa2f4d857ff3847d226c8a36da140cd3a81aa768c5d2d8
MD5 b67b68268bdfc15a6330a04a586cfc9f
BLAKE2b-256 46d61454a9b924cb9565fbb913875374cae9ab9a977a8ce79ec90ccc41b6c613

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