yattag


Nameyattag JSON
Version 1.16.1 PyPI version JSON
download
home_pagehttps://www.yattag.org
SummaryGenerate HTML or XML in a pythonic way. Pure python alternative to web template engines.Can fill HTML forms with default values and error messages.
upload_time2024-11-02 22:38:30
maintainerNone
docs_urlNone
authorBenjamin Le Forestier
requires_pythonNone
licenseNone
keywords html template templating xml document form rendering
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            .. image:: https://travis-ci.org/leforestier/yattag.svg
    :target: https://travis-ci.org/leforestier/yattag

Why use a template engine when you can generate HTML or XML documents with Python in a very readable way?

( full tutorial on yattag.org_ )

Basic example
-------------

Nested html tags, no need to close tags.

.. code:: python

    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
-------------------

Yattag can fill your HTML forms with default values and error messages.
Pass a ``defaults`` dictionary of default values, and an ``errors`` dictionary of error messages to the ``Doc`` constructor.
Then, use the special ``input``, ``textarea``, ``select``, ``option`` methods when generating your documents.


Example with default values
~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. code:: python

    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())

Example with default values and errors
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. code:: python

    from yattag import Doc

    doc, tag, text = Doc(
        defaults = {
            'title': 'Untitled',
            'contact_message': 'You just won the lottery!'
        },
        errors = {
            'contact_message': 'Your message looks like spam.'
        }
    ).tagtext()

    with tag('h1'):
        text('Contact form')
    with tag('form', action = ""):
        doc.input(name = 'title', type = 'text')
        with doc.textarea(name = 'contact_message'):
            pass
        doc.stag('input', type = 'submit', value = 'Send my message')

    print(doc.getvalue())

Full tutorial on yattag.org_

GitHub repo: https://github.com/leforestier/yattag

.. _yattag.org: https://www.yattag.org

            

Raw data

            {
    "_id": null,
    "home_page": "https://www.yattag.org",
    "name": "yattag",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "html, template, templating, xml, document, form, rendering",
    "author": "Benjamin Le Forestier",
    "author_email": "benjamin@leforestier.org",
    "download_url": "https://files.pythonhosted.org/packages/1c/1a/d3b2a2b8f843f5e7138471c4a5c9172ef62bb41239aa4371784b7448110c/yattag-1.16.1.tar.gz",
    "platform": null,
    "description": ".. image:: https://travis-ci.org/leforestier/yattag.svg\n    :target: https://travis-ci.org/leforestier/yattag\n\nWhy use a template engine when you can generate HTML or XML documents with Python in a very readable way?\n\n( full tutorial on yattag.org_ )\n\nBasic example\n-------------\n\nNested html tags, no need to close tags.\n\n.. code:: python\n\n    from yattag import Doc\n\n    doc, tag, text = Doc().tagtext()\n\n    with tag('html'):\n        with tag('body', id = 'hello'):\n            with tag('h1'):\n                text('Hello world!')\n\n    print(doc.getvalue())\n\n\nHtml form rendering\n-------------------\n\nYattag can fill your HTML forms with default values and error messages.\nPass a ``defaults`` dictionary of default values, and an ``errors`` dictionary of error messages to the ``Doc`` constructor.\nThen, use the special ``input``, ``textarea``, ``select``, ``option`` methods when generating your documents.\n\n\nExample with default values\n~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n.. code:: python\n\n    from yattag import Doc\n\n    doc, tag, text = Doc(\n        defaults = {'ingredient': ['chocolate', 'coffee']}\n    ).tagtext()\n\n    with tag('form', action = \"\"):\n        with tag('label'):\n            text(\"Select one or more ingredients\")\n        with doc.select(name = 'ingredient', multiple = \"multiple\"):\n            for value, description in (\n                (\"chocolate\", \"Dark chocolate\"),\n                (\"almonds\", \"Roasted almonds\"),\n                (\"honey\", \"Acacia honey\"),\n                (\"coffee\", \"Ethiopian coffee\")\n            ):\n                with doc.option(value = value):\n                    text(description)\n        doc.stag('input', type = \"submit\", value = \"Validate\")\n\n    print(doc.getvalue())\n\nExample with default values and errors\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n.. code:: python\n\n    from yattag import Doc\n\n    doc, tag, text = Doc(\n        defaults = {\n            'title': 'Untitled',\n            'contact_message': 'You just won the lottery!'\n        },\n        errors = {\n            'contact_message': 'Your message looks like spam.'\n        }\n    ).tagtext()\n\n    with tag('h1'):\n        text('Contact form')\n    with tag('form', action = \"\"):\n        doc.input(name = 'title', type = 'text')\n        with doc.textarea(name = 'contact_message'):\n            pass\n        doc.stag('input', type = 'submit', value = 'Send my message')\n\n    print(doc.getvalue())\n\nFull tutorial on yattag.org_\n\nGitHub repo: https://github.com/leforestier/yattag\n\n.. _yattag.org: https://www.yattag.org\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "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.",
    "version": "1.16.1",
    "project_urls": {
        "Homepage": "https://www.yattag.org"
    },
    "split_keywords": [
        "html",
        " template",
        " templating",
        " xml",
        " document",
        " form",
        " rendering"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1c1ad3b2a2b8f843f5e7138471c4a5c9172ef62bb41239aa4371784b7448110c",
                "md5": "2a48bb970f2f023159ba26cf2276cb09",
                "sha256": "baa8f254e7ea5d3e0618281ad2ff5610e0e5360b3608e695c29bfb3b29d051f4"
            },
            "downloads": -1,
            "filename": "yattag-1.16.1.tar.gz",
            "has_sig": false,
            "md5_digest": "2a48bb970f2f023159ba26cf2276cb09",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 29069,
            "upload_time": "2024-11-02T22:38:30",
            "upload_time_iso_8601": "2024-11-02T22:38:30.443024Z",
            "url": "https://files.pythonhosted.org/packages/1c/1a/d3b2a2b8f843f5e7138471c4a5c9172ef62bb41239aa4371784b7448110c/yattag-1.16.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-02 22:38:30",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "yattag"
}
        
Elapsed time: 2.47215s