Dominate is a Python library for creating and manipulating HTML documents using an elegant DOM API. It allows you to write HTML pages in pure Python v

Search code, repositories, users, issues, pull requests...

submited by
Style Pass
2024-12-14 03:30:05

Dominate is a Python library for creating and manipulating HTML documents using an elegant DOM API. It allows you to write HTML pages in pure Python very concisely, which eliminates the need to learn another template language, and lets you take advantage of the more powerful features of Python.

The most basic feature of dominate exposes a class for each HTML element, where the constructor accepts child elements, text, or keyword attributes. dominate nodes return their HTML representation from the __str__, __unicode__, and render() methods.

Dominate can also use keyword arguments to append attributes onto your tags. Most of the attributes are a direct copy from the HTML spec with a few variations.

This behavior can be controlled by the __pretty (default: True except for certain element types like pre) attribute when creating an element, and by the pretty (default: True), indent (default: ) and xhtml (default: False) arguments to render(). Rendering options propagate to all descendant nodes.

You can use this along with the other mechanisms of adding children elements, including nesting with statements, and it works as expected:

Leave a Comment