Skip to content

Latest commit

 

History

History
63 lines (49 loc) · 1.73 KB

html.rst

File metadata and controls

63 lines (49 loc) · 1.73 KB

Template helpers (bottle_utils.html)

Contents of this module are mostly meant to be used inside the view templates, but their usage is not limited to templates by any means. bottle_utils.html contains a few data-formatting functions as well as shortcuts for generating HTML snippets and binding data to form fields.

Basic usage

One way to make the module contents available to templates is to add the module itself as a default template variable.:

import bottle
from bottle_utils import html
bottle.BaseTemplate.defaults['h'] = html

This allows you to use the module members by access the h variable in templates:

<html {{! h.attr('lang', request.locale }}>

Note

If your tempate engine auto-escapes HTML, you need to instruct it to unescape strings gneerated by some of the helper functions. For instance, in Bottle's SimpleTemplate engine, you need to enclose the strings in {{! }}.

Data formatting

bottle_utils.html

hsize

plur

strft

trunc

yesno

HTML rendering

tag

link_other(label, url, path, wrapper=lambda l, kw: l,*kwargs)

vinput

varea

vcheckbox

vselect

form

URL handling

QueryDict

add_qparam

set_qparam

del_qparam

urlquote

urlunquote

quote_dict

quoted_url