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.3.zip (8.1 kB view details)

Uploaded Source

yattag-0.8.3.tar.gz (5.9 kB view details)

Uploaded Source

File details

Details for the file yattag-0.8.3.zip.

File metadata

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

File hashes

Hashes for yattag-0.8.3.zip
Algorithm Hash digest
SHA256 a5d484cbef5b2ba664823d3a4c2691224746b4d0873eeb6078cf8bfa2ed3fe24
MD5 21265e7d9e2a14bb91c9fa590b365f55
BLAKE2b-256 bb8464d093ef4451fb591e1d74e780048d2c74b6f2a2a521c09e4a2db57a58ee

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for yattag-0.8.3.tar.gz
Algorithm Hash digest
SHA256 8d26def52ccc35e195ef005b49028a68edab948d0df63b79709f81c7f13089c6
MD5 cef74ac4876234a6395d8c790f0eb159
BLAKE2b-256 37399282c95677ac14bbada868c051db9935e4b3fc20334cccb89915707065de

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