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.9.0.zip (8.5 kB view details)

Uploaded Source

yattag-0.9.0.tar.gz (6.3 kB view details)

Uploaded Source

File details

Details for the file yattag-0.9.0.zip.

File metadata

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

File hashes

Hashes for yattag-0.9.0.zip
Algorithm Hash digest
SHA256 11a2731a2a8f50cf9c89e87a782c40c11662b2cee1475992e48a2893f42c2d8d
MD5 b7555e39fa4dbecde5f66e048759903d
BLAKE2b-256 fdf26ac4d07f23e38530b7220fe8261d5b17f47d95093b31272d50aa7c3d5ab2

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for yattag-0.9.0.tar.gz
Algorithm Hash digest
SHA256 c8164e5a2996bea3bebf53290d5ef1f6a7b12ee7a713a43ae93e61a33164cc2c
MD5 24197721185c3bf315e7b44140c04b8c
BLAKE2b-256 6d4e58b416f490d2708e7b284b5b17e50d44a13a733439bb5cfd17ac73707773

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