tags

Tag Helpers

Use these methods to generate XHTML comliant tags programmatically.


Functions

f camelize(name) ...

Camelize a name

f tag(name, open=False, **options) ...

Returns an XHTML compliant tag of type name.

open
Set to True if the tag should remain open

All additional keyword args become attribute/value's for the tag. To pass in Python reserved words, append _ to the name of the key. For attributes with no value (such as disabled and readonly), a value of True is permitted.

Examples:

>>> tag("br")
'<br />'
>>> tag("br", True)
'<br>'
>>> tag("input", type="text")
'<input type="text" />'
>>> tag("input", type='text', disabled=True)
'<input disabled="disabled" type="text" />'

f content_tag(name, content, **options) ...

Create a tag with content

Takes the same keyword args as tag

Examples:

>>> content_tag("p", "Hello world!")
'<p>Hello world!</p>'
>>> content_tag("div", content_tag("p", "Hello world!"), class_="strong")
'<div class="strong"><p>Hello world!</p></div>'

f cdata_section(content) ...

Returns a CDATA section with the given content.

CDATA sections are used to escape blocks of text containing characters which would otherwise be recognized as markup. CDATA sections begin with the string <![CDATA[ and end with (and may not contain) the string ]]>.

f escape_once(html) ...

Escapes a given string without affecting existing escaped entities.

>>> escape_once("1 < 2 &amp; 3")
'1 &lt; 2 &amp; 3'

See the source for more information.