html
Module¶
Template helpers¶
-
class
gluon.html.
A
(*components, **attributes)[source]¶ Bases:
gluon.html.DIV
Generates an A() link. A() in web2py is really important and with the included web2py.js allows lots of Ajax interactions in the page
On top of “usual” _attributes, it takes
Parameters: - callback – an url to call but not redirect to
- cid – if you want to load the _href into an element of the page (component) pass its id (without the #) here
- delete – element to delete after calling callback
- target – same thing as cid
- confirm – text to display upon a callback with a delete
- noconfirm – don’t display alert upon a callback with delete
-
tag
= 'a'¶
-
gluon.html.
ASSIGNJS
(**kargs)[source]¶ Example
ASSIGNJS(var1=‘1’, var2=‘2’) will return the following javascript variables assignations :
var var1 = “1”; var var2 = “2”;Parameters: **kargs – Any keywords arguments and assigned values. Returns: Javascript vars assignations for the key/value passed.
-
class
gluon.html.
B
(*components, **attributes)[source]¶ Bases:
gluon.html.DIV
-
tag
= 'b'¶
-
-
class
gluon.html.
BEAUTIFY
(component, **attributes)[source]¶ Bases:
gluon.html.DIV
Turns any list, dictionary, etc into decent looking html.
Two special attributes are
- sorted: a function that takes the dict and returned sorted keys
- keyfilter: a function that takes a key and returns its representation or None if the key is to be skipped. By default key[:1]==’_’ is skipped.
Examples:
>>> BEAUTIFY(['a', 'b', {'hello': 'world'}]).xml() '<div><table><tr><td><div>a</div></td></tr><tr><td><div>b</div></td></tr><tr><td><div><table><tr><td style="font-weight:bold;vertical-align:top;">hello</td><td style="vertical-align:top;">:</td><td><div>world</div></td></tr></table></div></td></tr></table></div>'
-
tag
= 'div'¶
-
class
gluon.html.
BODY
(*components, **attributes)[source]¶ Bases:
gluon.html.DIV
-
tag
= 'body'¶
-
-
class
gluon.html.
BR
(*components, **attributes)[source]¶ Bases:
gluon.html.DIV
-
tag
= 'br/'¶
-
-
class
gluon.html.
BUTTON
(*components, **attributes)[source]¶ Bases:
gluon.html.DIV
-
tag
= 'button'¶
-
-
class
gluon.html.
CENTER
(*components, **attributes)[source]¶ Bases:
gluon.html.DIV
-
tag
= 'center'¶
-
-
class
gluon.html.
CAT
(*components, **attributes)[source]¶ Bases:
gluon.html.DIV
-
tag
= ''¶
-
-
class
gluon.html.
CODE
(*components, **attributes)[source]¶ Bases:
gluon.html.DIV
Displays code in HTML with syntax highlighting.
Parameters: - language – indicates the language, otherwise PYTHON is assumed
- link – can provide a link
- styles – for styles
Examples:
- {{=CODE(“print ‘hello world’”, language=’python’, link=None,
- counter=1, styles={}, highlight_line=None)}}
supported languages are
“python”, “html_plain”, “c”, “cpp”, “web2py”, “html”The “html” language interprets {{ and }} tags as “web2py” code, “html_plain” doesn’t.
if a link=’/examples/global/vars/’ is provided web2py keywords are linked to the online docs.
the counter is used for line numbering, counter can be None or a prompt string.
-
class
gluon.html.
COL
(*components, **attributes)[source]¶ Bases:
gluon.html.DIV
-
tag
= 'col/'¶
-
-
class
gluon.html.
COLGROUP
(*components, **attributes)[source]¶ Bases:
gluon.html.DIV
-
tag
= 'colgroup'¶
-
-
class
gluon.html.
DIV
(*components, **attributes)[source]¶ Bases:
gluon.html.XmlComponent
HTML helper, for easy generating and manipulating a DOM structure. Little or no validation is done.
Behaves like a dictionary regarding updating of attributes. Behaves like a list regarding inserting/appending components.
Examples:
>>> DIV('hello', 'world', _style='color:red;').xml() '<div style="color:red;">helloworld</div>'
All other HTML helpers are derived from DIV.
_something=”value” attributes are transparently translated into something=”value” HTML attributes
-
append
(value)[source]¶ list style appending of components
Examples:
>>> a=DIV() >>> a.append(SPAN('x')) >>> print a <div><span>x</span></div>
-
element
(*args, **kargs)[source]¶ Finds the first component that matches the supplied attribute dictionary, or None if nothing could be found
Also the components of the components are searched.
-
elements
(*args, **kargs)[source]¶ Find all components that match the supplied attribute dictionary, or None if nothing could be found
All components of the components are searched.
Examples:
>>> a = DIV(DIV(SPAN('x'),3,DIV(SPAN('y')))) >>> for c in a.elements('span', first_only=True): c[0]='z' >>> print a <div><div><span>z</span>3<div><span>y</span></div></div></div> >>> for c in a.elements('span'): c[0]='z' >>> print a <div><div><span>z</span>3<div><span>z</span></div></div></div>
It also supports a syntax compatible with jQuery
Examples:
>>> a=TAG('<div><span><a id="1-1" u:v=$>hello</a></span><p class="this is a test">world</p></div>') >>> for e in a.elements('div a#1-1, p.is'): print e.flatten() hello world >>> for e in a.elements('#1-1'): print e.flatten() hello >>> a.elements('a[u:v=$]')[0].xml() '<a id="1-1" u:v="$">hello</a>' >>> a=FORM( INPUT(_type='text'), SELECT(range(1)), TEXTAREA() ) >>> for c in a.elements('input, select, textarea'): c['_disabled'] = 'disabled' >>> a.xml() '<form action="#" enctype="multipart/form-data" method="post"><input disabled="disabled" type="text" /><select disabled="disabled"><option value="0">0</option></select><textarea cols="40" disabled="disabled" rows="10"></textarea></form>'
Elements that are matched can also be replaced or removed by specifying a “replace” argument (note, a list of the original matching elements is still returned as usual).
Examples:
>>> a = DIV(DIV(SPAN('x', _class='abc'), DIV(SPAN('y', _class='abc'), SPAN('z', _class='abc')))) >>> b = a.elements('span.abc', replace=P('x', _class='xyz')) >>> print a # We should .xml() here instead of print <div><div><p class="xyz">x</p><div><p class="xyz">x</p><p class="xyz">x</p></div></div></div>
“replace” can be a callable, which will be passed the original element and should return a new element to replace it.
Examples:
>>> a = DIV(DIV(SPAN('x', _class='abc'), DIV(SPAN('y', _class='abc'), SPAN('z', _class='abc')))) >>> b = a.elements('span.abc', replace=lambda el: P(el[0], _class='xyz')) >>> print a <div><div><p class="xyz">x</p><div><p class="xyz">y</p><p class="xyz">z</p></div></div></div>
If replace=None, matching elements will be removed completely.
Examples:
>>> a = DIV(DIV(SPAN('x', _class='abc'), DIV(SPAN('y', _class='abc'), SPAN('z', _class='abc')))) >>> b = a.elements('span', find='y', replace=None) >>> print a <div><div><span class="abc">x</span><div><span class="abc">z</span></div></div></div>
If a “find_text” argument is specified, elements will be searched for text components that match find_text, and any matching text components will be replaced (find_text is ignored if “replace” is not also specified). Like the “find” argument, “find_text” can be a string or a compiled regex.
Examples:
>>> a = DIV(DIV(SPAN('x', _class='abc'), DIV(SPAN('y', _class='abc'), SPAN('z', _class='abc')))) >>> b = a.elements(find_text=re.compile('x|y|z'), replace='hello') >>> print a <div><div><span class="abc">hello</span><div><span class="abc">hello</span><span class="abc">hello</span></div></div></div>
If other attributes are specified along with find_text, then only components that match the specified attributes will be searched for find_text.
Examples:
>>> a = DIV(DIV(SPAN('x', _class='abc'), DIV(SPAN('y', _class='efg'), SPAN('z', _class='abc')))) >>> b = a.elements('span.efg', find_text=re.compile('x|y|z'), replace='hello') >>> print a <div><div><span class="abc">x</span><div><span class="efg">hello</span><span class="abc">z</span></div></div></div>
-
flatten
(render=None)[source]¶ Returns the text stored by the DIV object rendered by the render function the render function must take text, tagname, and attributes render=None is equivalent to render=lambda text, tag, attr: text
Examples:
>>> markdown = lambda text, tag=None, attributes={}: {None: re.sub('\s+',' ',text), 'h1':'#'+text+'\n\n', 'p':text+'\n'}.get(tag,text) >>> a=TAG('<h1>Header</h1><p>this is a test</p>') >>> a.flatten(markdown) '#Header\n\nthis is a test\n'
-
insert
(i, value)[source]¶ List-style inserting of components
Examples:
>>> a=DIV() >>> a.insert(0, SPAN('x')) >>> print a <div><span>x</span></div>
-
regex_attr
= <_sre.SRE_Pattern object>¶
-
regex_class
= <_sre.SRE_Pattern object>¶
-
regex_id
= <_sre.SRE_Pattern object>¶
-
regex_tag
= <_sre.SRE_Pattern object>¶
-
sibling
(*args, **kargs)[source]¶ Finds the first sibling component that match the supplied argument list and attribute dictionary, or None if nothing could be found
-
siblings
(*args, **kargs)[source]¶ Finds all sibling components that match the supplied argument list and attribute dictionary, or None if nothing could be found
-
tag
= 'div'¶
-
-
class
gluon.html.
EM
(*components, **attributes)[source]¶ Bases:
gluon.html.DIV
-
tag
= 'em'¶
-
-
class
gluon.html.
EMBED
(*components, **attributes)[source]¶ Bases:
gluon.html.DIV
-
tag
= 'embed/'¶
-
-
class
gluon.html.
FIELDSET
(*components, **attributes)[source]¶ Bases:
gluon.html.DIV
-
tag
= 'fieldset'¶
-
-
class
gluon.html.
FORM
(*components, **attributes)[source]¶ Bases:
gluon.html.DIV
Examples:
>>> from validators import IS_NOT_EMPTY >>> form=FORM(INPUT(_name="test", requires=IS_NOT_EMPTY())) >>> form.xml() '<form action="#" enctype="multipart/form-data" method="post"><input name="test" type="text" /></form>'
a FORM is container for INPUT, TEXTAREA, SELECT and other helpers
form has one important method:
form.accepts(request.vars, session)
if form is accepted (and all validators pass) form.vars contains the accepted vars, otherwise form.errors contains the errors. in case of errors the form is modified to present the errors to the user.
-
REDIRECT_JS
= "window.location='%s';return false"¶
-
accepts
(request_vars, session=None, formname='default', keepvalues=False, onvalidation=None, hideerror=False, **kwargs)[source]¶ kwargs is not used but allows to specify the same interface for FORM and SQLFORM
-
as_dict
(flat=False, sanitize=True)[source]¶ EXPERIMENTAL
Sanitize is naive. It should catch any unsafe value for client retrieval.
-
process
(**kwargs)[source]¶ Perform the .validate() method but returns the form
Usage in controllers:
# directly on return def action(): #some code here return dict(form=FORM(...).process(...))
You can use it with FORM, SQLFORM or FORM based plugins:
# response.flash messages def action(): form = SQLFORM(db.table).process(message_onsuccess='Sucess!') return dict(form=form) # callback function # callback receives True or False as first arg, and a list of args. def my_callback(status, msg): response.flash = "Success! "+msg if status else "Errors occured" # after argument can be 'flash' to response.flash messages # or a function name to use as callback or None to do nothing. def action(): return dict(form=SQLFORM(db.table).process(onsuccess=my_callback)
-
tag
= 'form'¶
-
validate
(**kwargs)[source]¶ This function validates the form, you can use it instead of directly form.accepts.
Usage: In controller:
def action(): form=FORM(INPUT(_name="test", requires=IS_NOT_EMPTY())) form.validate() #you can pass some args here - see below return dict(form=form)
This can receive a bunch of arguments
- onsuccess = ‘flash’ - will show message_onsuccess in response.flash
- None - will do nothing can be a function (lambda form: pass)
- onfailure = ‘flash’ - will show message_onfailure in response.flash
- None - will do nothing can be a function (lambda form: pass)
- onchange = ‘flash’ - will show message_onchange in response.flash
- None - will do nothing can be a function (lambda form: pass)
message_onsuccess message_onfailure message_onchange next = where to redirect in case of success any other kwargs will be passed for form.accepts(…)
-
-
class
gluon.html.
H1
(*components, **attributes)[source]¶ Bases:
gluon.html.DIV
-
tag
= 'h1'¶
-
-
class
gluon.html.
H2
(*components, **attributes)[source]¶ Bases:
gluon.html.DIV
-
tag
= 'h2'¶
-
-
class
gluon.html.
H3
(*components, **attributes)[source]¶ Bases:
gluon.html.DIV
-
tag
= 'h3'¶
-
-
class
gluon.html.
H4
(*components, **attributes)[source]¶ Bases:
gluon.html.DIV
-
tag
= 'h4'¶
-
-
class
gluon.html.
H5
(*components, **attributes)[source]¶ Bases:
gluon.html.DIV
-
tag
= 'h5'¶
-
-
class
gluon.html.
H6
(*components, **attributes)[source]¶ Bases:
gluon.html.DIV
-
tag
= 'h6'¶
-
-
class
gluon.html.
HEAD
(*components, **attributes)[source]¶ Bases:
gluon.html.DIV
-
tag
= 'head'¶
-
-
class
gluon.html.
HR
(*components, **attributes)[source]¶ Bases:
gluon.html.DIV
-
tag
= 'hr/'¶
-
-
class
gluon.html.
HTML
(*components, **attributes)[source]¶ Bases:
gluon.html.DIV
There are four predefined document type definitions. They can be specified in the ‘doctype’ parameter:
- ‘strict’ enables strict doctype
- ‘transitional’ enables transitional doctype (default)
- ‘frameset’ enables frameset doctype
- ‘html5’ enables HTML 5 doctype
- any other string will be treated as user’s own doctype
‘lang’ parameter specifies the language of the document. Defaults to ‘en’.
See also DIV
-
frameset
= '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">\n'¶
-
html5
= '<!DOCTYPE HTML>\n'¶
-
strict
= '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">\n'¶
-
tag
= 'html'¶
-
transitional
= '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">\n'¶
-
class
gluon.html.
I
(*components, **attributes)[source]¶ Bases:
gluon.html.DIV
-
tag
= 'i'¶
-
-
class
gluon.html.
IFRAME
(*components, **attributes)[source]¶ Bases:
gluon.html.DIV
-
tag
= 'iframe'¶
-
-
class
gluon.html.
IMG
(*components, **attributes)[source]¶ Bases:
gluon.html.DIV
-
tag
= 'img/'¶
-
-
class
gluon.html.
INPUT
(*components, **attributes)[source]¶ Bases:
gluon.html.DIV
INPUT Component
Takes two special attributes value= and requires=.
Parameters: - value – used to pass the initial value for the input field. value differs from _value because it works for checkboxes, radio, textarea and select/option too. For a checkbox value should be ‘’ or ‘on’. For a radio or select/option value should be the _value of the checked/selected item.
- requires – should be None, or a validator or a list of validators for the value of the field.
Examples:
>>> INPUT(_type='text', _name='name', value='Max').xml() '<input name="name" type="text" value="Max" />'
>>> INPUT(_type='checkbox', _name='checkbox', value='on').xml() '<input checked="checked" name="checkbox" type="checkbox" value="on" />'
>>> INPUT(_type='radio', _name='radio', _value='yes', value='yes').xml() '<input checked="checked" name="radio" type="radio" value="yes" />'
>>> INPUT(_type='radio', _name='radio', _value='no', value='yes').xml() '<input name="radio" type="radio" value="no" />'
-
tag
= 'input/'¶
-
class
gluon.html.
LABEL
(*components, **attributes)[source]¶ Bases:
gluon.html.DIV
-
tag
= 'label'¶
-
-
class
gluon.html.
LEGEND
(*components, **attributes)[source]¶ Bases:
gluon.html.DIV
-
tag
= 'legend'¶
-
-
class
gluon.html.
LI
(*components, **attributes)[source]¶ Bases:
gluon.html.DIV
-
tag
= 'li'¶
-
-
class
gluon.html.
LINK
(*components, **attributes)[source]¶ Bases:
gluon.html.DIV
-
tag
= 'link/'¶
-
-
class
gluon.html.
OL
(*components, **attributes)[source]¶ Bases:
gluon.html.UL
-
tag
= 'ol'¶
-
-
class
gluon.html.
UL
(*components, **attributes)[source]¶ Bases:
gluon.html.DIV
UL Component.
If subcomponents are not LI-components they will be wrapped in a LI
-
tag
= 'ul'¶
-
-
class
gluon.html.
MARKMIN
(text, extra=None, allowed=None, sep='p', url=None, environment=None, latex='google', autolinks='default', protolinks='default', class_prefix='', id_prefix='markmin_', **kwargs)[source]¶ Bases:
gluon.html.XmlComponent
For documentation: http://web2py.com/examples/static/markmin.html
-
class
gluon.html.
MENU
(data, **args)[source]¶ Bases:
gluon.html.DIV
Used to build menus
Parameters: - _class – defaults to ‘web2py-menu web2py-menu-vertical’
- ul_class – defaults to ‘web2py-menu-vertical’
- li_class – defaults to ‘web2py-menu-expand’
- li_first – defaults to ‘web2py-menu-first’
- li_last – defaults to ‘web2py-menu-last’
Use like:
menu = MENU([['name', False, URL(...), [submenu]], ...]) {{=menu}}
-
tag
= 'ul'¶
-
class
gluon.html.
META
(*components, **attributes)[source]¶ Bases:
gluon.html.DIV
-
tag
= 'meta/'¶
-
-
class
gluon.html.
OBJECT
(*components, **attributes)[source]¶ Bases:
gluon.html.DIV
-
tag
= 'object'¶
-
-
class
gluon.html.
OPTION
(*components, **attributes)[source]¶ Bases:
gluon.html.DIV
-
tag
= 'option'¶
-
-
class
gluon.html.
P
(*components, **attributes)[source]¶ Bases:
gluon.html.DIV
Will replace
\n
by<br />
if the cr2br attribute is provided.see also DIV
-
tag
= 'p'¶
-
-
class
gluon.html.
PRE
(*components, **attributes)[source]¶ Bases:
gluon.html.DIV
-
tag
= 'pre'¶
-
-
class
gluon.html.
SCRIPT
(*components, **attributes)[source]¶ Bases:
gluon.html.DIV
-
tag
= 'script'¶
-
-
class
gluon.html.
OPTGROUP
(*components, **attributes)[source]¶ Bases:
gluon.html.DIV
-
tag
= 'optgroup'¶
-
-
class
gluon.html.
SELECT
(*components, **attributes)[source]¶ Bases:
gluon.html.INPUT
Examples:
>>> from validators import IS_IN_SET >>> SELECT('yes', 'no', _name='selector', value='yes', ... requires=IS_IN_SET(['yes', 'no'])).xml() '<select name="selector"><option selected="selected" value="yes">yes</option><option value="no">no</option></select>'
-
tag
= 'select'¶
-
-
class
gluon.html.
SPAN
(*components, **attributes)[source]¶ Bases:
gluon.html.DIV
-
tag
= 'span'¶
-
-
class
gluon.html.
STRONG
(*components, **attributes)[source]¶ Bases:
gluon.html.DIV
-
tag
= 'strong'¶
-
-
class
gluon.html.
STYLE
(*components, **attributes)[source]¶ Bases:
gluon.html.DIV
-
tag
= 'style'¶
-
-
class
gluon.html.
TABLE
(*components, **attributes)[source]¶ Bases:
gluon.html.DIV
TABLE Component.
If subcomponents are not TR/TBODY/THEAD/TFOOT-components they will be wrapped in a TR
-
tag
= 'table'¶
-
-
gluon.html.
TAG
¶ TAG factory
Examples:
>>> print TAG.first(TAG.second('test'), _key = 3) <first key="3"><second>test</second></first>
-
class
gluon.html.
TD
(*components, **attributes)[source]¶ Bases:
gluon.html.DIV
-
tag
= 'td'¶
-
-
class
gluon.html.
TEXTAREA
(*components, **attributes)[source]¶ Bases:
gluon.html.INPUT
Examples:
TEXTAREA(_name='sometext', value='blah ' * 100, requires=IS_NOT_EMPTY())
‘blah blah blah …’ will be the content of the textarea field.
-
tag
= 'textarea'¶
-
-
class
gluon.html.
TH
(*components, **attributes)[source]¶ Bases:
gluon.html.DIV
-
tag
= 'th'¶
-
-
class
gluon.html.
THEAD
(*components, **attributes)[source]¶ Bases:
gluon.html.DIV
-
tag
= 'thead'¶
-
-
class
gluon.html.
TBODY
(*components, **attributes)[source]¶ Bases:
gluon.html.DIV
-
tag
= 'tbody'¶
-
-
class
gluon.html.
TFOOT
(*components, **attributes)[source]¶ Bases:
gluon.html.DIV
-
tag
= 'tfoot'¶
-
-
class
gluon.html.
TITLE
(*components, **attributes)[source]¶ Bases:
gluon.html.DIV
-
tag
= 'title'¶
-
-
class
gluon.html.
TR
(*components, **attributes)[source]¶ Bases:
gluon.html.DIV
TR Component.
If subcomponents are not TD/TH-components they will be wrapped in a TD
-
tag
= 'tr'¶
-
-
class
gluon.html.
TT
(*components, **attributes)[source]¶ Bases:
gluon.html.DIV
-
tag
= 'tt'¶
-
-
gluon.html.
URL
(a=None, c=None, f=None, r=None, args=None, vars=None, anchor='', extension=None, env=None, hmac_key=None, hash_vars=True, salt=None, user_signature=None, scheme=None, host=None, port=None, encode_embedded_slash=False, url_encode=True, language=None)[source]¶ generates a url ‘/a/c/f’ corresponding to application a, controller c and function f. If r=request is passed, a, c, f are set, respectively, to r.application, r.controller, r.function.
The more typical usage is:
URL(‘index’)that generates a url for the index function within the present application and controller.
Parameters: - a – application (default to current if r is given)
- c – controller (default to current if r is given)
- f – function (default to current if r is given)
- r – request (optional)
- args – any arguments (optional). Additional “path” elements
- vars – any variables (optional). Querystring elements
- anchor – anchorname, without # (optional)
- extension – force an extension
- hmac_key – key to use when generating hmac signature (optional)
- hash_vars – which of the vars to include in our hmac signature True (default) - hash all vars, False - hash none of the vars, iterable - hash only the included vars [‘key1’,’key2’]
- salt – salt hashing with this string
- user_signature – signs automatically the URL in such way that only the user can access the URL (use with URL.verify or auth.requires_signature())
- scheme – URI scheme (True, ‘http’ or ‘https’, etc); forces absolute URL (optional)
- host – string to force absolute URL with host (True means http_host)
- port – optional port number (forces absolute URL)
- encode_embedded_slash – encode slash characters included in args
- url_encode – encode characters included in vars
Raises: SyntaxError – when no application, controller or function is available or when a CRLF is found in the generated url
Examples:
>>> str(URL(a='a', c='c', f='f', args=['x', 'y', 'z'], ... vars={'p':1, 'q':2}, anchor='1')) '/a/c/f/x/y/z?p=1&q=2#1'
>>> str(URL(a='a', c='c', f='f', args=['x', 'y', 'z'], ... vars={'p':(1,3), 'q':2}, anchor='1')) '/a/c/f/x/y/z?p=1&p=3&q=2#1'
>>> str(URL(a='a', c='c', f='f', args=['x', 'y', 'z'], ... vars={'p':(3,1), 'q':2}, anchor='1')) '/a/c/f/x/y/z?p=3&p=1&q=2#1'
>>> str(URL(a='a', c='c', f='f', anchor='1+2')) '/a/c/f#1%2B2'
>>> str(URL(a='a', c='c', f='f', args=['x', 'y', 'z'], ... vars={'p':(1,3), 'q':2}, anchor='1', hmac_key='key')) '/a/c/f/x/y/z?p=1&p=3&q=2&_signature=a32530f0d0caa80964bb92aad2bedf8a4486a31f#1'
>>> str(URL(a='a', c='c', f='f', args=['w/x', 'y/z'])) '/a/c/f/w/x/y/z'
>>> str(URL(a='a', c='c', f='f', args=['w/x', 'y/z'], encode_embedded_slash=True)) '/a/c/f/w%2Fx/y%2Fz'
>>> str(URL(a='a', c='c', f='f', args=['%(id)d'], url_encode=False)) '/a/c/f/%(id)d'
>>> str(URL(a='a', c='c', f='f', args=['%(id)d'], url_encode=True)) '/a/c/f/%25%28id%29d'
>>> str(URL(a='a', c='c', f='f', vars={'id' : '%(id)d' }, url_encode=False)) '/a/c/f?id=%(id)d'
>>> str(URL(a='a', c='c', f='f', vars={'id' : '%(id)d' }, url_encode=True)) '/a/c/f?id=%25%28id%29d'
>>> str(URL(a='a', c='c', f='f', anchor='%(id)d', url_encode=False)) '/a/c/f#%(id)d'
>>> str(URL(a='a', c='c', f='f', anchor='%(id)d', url_encode=True)) '/a/c/f#%25%28id%29d'
-
class
gluon.html.
XHTML
(*components, **attributes)[source]¶ Bases:
gluon.html.DIV
This is XHTML version of the HTML helper.
There are three predefined document type definitions. They can be specified in the ‘doctype’ parameter:
- ‘strict’ enables strict doctype
- ‘transitional’ enables transitional doctype (default)
- ‘frameset’ enables frameset doctype
- any other string will be treated as user’s own doctype
‘lang’ parameter specifies the language of the document and the xml document. Defaults to ‘en’.
‘xmlns’ parameter specifies the xml namespace. Defaults to ‘http://www.w3.org/1999/xhtml’.
See also DIV
-
frameset
= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">\n'¶
-
strict
= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n'¶
-
tag
= 'html'¶
-
transitional
= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n'¶
-
xmlns
= 'http://www.w3.org/1999/xhtml'¶
-
class
gluon.html.
XML
(text, sanitize=False, permitted_tags=['a', 'b', 'blockquote', 'br/', 'i', 'li', 'ol', 'ul', 'p', 'cite', 'code', 'pre', 'img/', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'table', 'tr', 'td', 'div', 'strong', 'span'], allowed_attributes={'a': ['href', 'title', 'target'], 'blockquote': ['type'], 'img': ['src', 'alt'], 'td': ['colspan']})[source]¶ Bases:
gluon.html.XmlComponent
use it to wrap a string that contains XML/HTML so that it will not be escaped by the template
Examples:
>>> XML('<h1>Hello</h1>').xml() '<h1>Hello</h1>'
-
elements
(*args, **kargs)[source]¶ to be considered experimental since the behavior of this method is questionable another option could be TAG(self.text).elements(*args, **kwargs)
-