OOP Python Templating Engine.


View the Project on GitHub

This project is maintained by Hrabal

Hosted on GitHub Pages — Theme by orderedlist

Tag Creation

Create DOM elements by instantiating tag classes. Those elements are nodes in the DOM tree and can be attached, detached, moved and composed together dynamically.

There are 2 other ways to create TemPy objects:

page = Html()
div = Div()

new_page = page.clone()

new_page_2 = page + div
new_page_3 = new_page_2 - div
list_of_5_divs = div * 5

TemPy Tags

TemPy provides a class for every HTML5 element defined in the W3C reference, those classes can be imported from the tempy.tags submodule.

Each Tempy Tag class is either a tempy.elements.Tag with a start tag and an end tag, that can contain something, or a tempy.elements.VoidTag that can not contain other things and is composed of a single html tag mark.

from tempy.tags import Div, Br

Div.render()  # Subclass of tempy.elements.Tag
>>> <div></div>

Br.render()  # Subclass of tempy.elements.VoidTag
>>> <br/>

A few TemPy tags have custom behavior: