html 模块

此文件是Web2py Web框架的一部分
版权所有:Massimo di Pierro<mdipierro@cs.depaul.edu>

模板帮助程序

class gluon.html.A(*components, **attributes)[源代码]

基类:gluon.html.DIV

生成a()链接。web2py中的a()非常重要,其中包含web2py.js允许在页面中进行大量的Ajax交互。

在“平常”之上 _attributes 它需要

参数
  • callback -- 要调用但不重定向到的URL

  • cid -- 如果要将_href加载到页面(组件)的元素中,请在此处传递其ID(不带)。

  • delete -- 调用回调后要删除的元素

  • target -- 和cid一样

  • confirm -- 在回调时显示的带删除的文本

  • noconfirm -- 不在使用delete的回调时显示警报

tag = 'a'
xml()[源代码]

为此组件生成XML。

gluon.html.ASSIGNJS(**kargs)[源代码]

例子

assignJS(var1='1',var2='2')将返回以下javascript变量赋值:

var var1=“1”;var var2=“2”;

参数

**kargs -- 任何关键字参数和赋值。

返回

为传递的键/值分配的javascript变量。

class gluon.html.B(*components, **attributes)[源代码]

基类:gluon.html.DIV

tag = 'b'
class gluon.html.BEAUTIFY(component, **attributes)[源代码]

基类:gluon.html.DIV

将任何列表、字典等转换为外观良好的HTML。

两个特殊属性是

  • sorted:接受dict并返回排序键的函数。

  • keyfilter:接受一个键并返回其表示形式的函数,如果要跳过该键,则返回none。默认键 [:1] ==''跳过。

实例:

>>> 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>'
static no_underscore(key)[源代码]
tag = 'div'
class gluon.html.BODY(*components, **attributes)[源代码]

基类:gluon.html.DIV

tag = 'body'
class gluon.html.BR(*components, **attributes)[源代码]

基类:gluon.html.DIV

tag = 'br/'
class gluon.html.BUTTON(*components, **attributes)[源代码]

基类:gluon.html.DIV

tag = 'button'
class gluon.html.CAT(*components, **attributes)[源代码]

基类:gluon.html.DIV

tag = ''
class gluon.html.CENTER(*components, **attributes)[源代码]

基类:gluon.html.DIV

tag = 'center'
class gluon.html.CODE(*components, **attributes)[源代码]

基类:gluon.html.DIV

以HTML格式显示代码,并突出显示语法。

参数
  • language -- 指示语言,否则假定为python

  • link -- 可以提供链接

  • styles -- 为风格

实例:

=code(“print('hello world')”,language='python',link=none,

counter=1,styles=,highlight_line=none)

支持的语言是

“python”,“html-plain”,“c”,“cpp”,“web2py”,“html”

“html”语言将和标记解释为“web2py”代码,而“html plain”则没有。

如果提供了link='/examples/global/vars/,web2py关键字将链接到联机文档。

计数器用于行编号,计数器可以是无或提示字符串。

xml()[源代码]

为此组件生成XML。

class gluon.html.COL(*components, **attributes)[源代码]

基类:gluon.html.DIV

tag = 'col/'
class gluon.html.COLGROUP(*components, **attributes)[源代码]

基类:gluon.html.DIV

tag = 'colgroup'
class gluon.html.DIV(*components, **attributes)[源代码]

基类:gluon.html.XmlComponent

HTML助手,用于轻松生成和操作DOM结构。很少或没有进行验证。

行为类似于更新属性的字典。行为类似于插入/附加组件的列表。

实例:

>>> DIV('hello', 'world', _style='color:red;').xml()
'<div style="color:red;">helloworld</div>'

所有其他HTML助手都是从 DIV .

_something="value" 属性被透明地转换为 something="value" HTML属性

append(value)[源代码]

组件的列表样式附加

实例:

>>> a=DIV()
>>> a.append(SPAN('x'))
>>> print(a)
<div><span>x</span></div>
element(*args, **kargs)[源代码]

查找与提供的属性字典匹配的第一个组件,如果找不到任何组件,则查找“无”

同时搜索组件的组件。

elements(*args, **kargs)[源代码]

查找与提供的属性字典匹配的所有组件;如果找不到任何组件,则查找无组件。

搜索所有组件。

实例:

>>> 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>

它还支持与jquery兼容的语法

实例:

>>> 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(list(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>'

匹配的元素也可以通过指定“replace”参数来替换或删除(注意,原始匹配元素的列表仍然像往常一样返回)。

实例:

>>> 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”可以是可调用的,它将传递原始元素,并应返回一个新元素来替换它。

实例:

>>> 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>

如果replace=none,匹配的元素将被完全删除。

实例:

>>> 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>

如果指定了“find_text”参数,则将在元素中搜索与find_text匹配的文本组件,并替换任何匹配的文本组件(如果未指定“replace”,则忽略find_text)。像“find”参数一样,“find_text”可以是字符串或编译的regex。

实例:

>>> 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>

如果其他属性与查找文本一起指定,则只搜索与指定属性匹配的组件以查找查找文本。

实例:

>>> 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)[源代码]

返回由呈现函数呈现的DIV对象存储的文本。呈现函数必须具有文本、标记名和属性。 render=None 等于 render=lambda text, tag, attr: text

实例:

>>> 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'
get(i)[源代码]
insert(i, value)[源代码]

组件的列表样式插入

实例:

>>> a=DIV()
>>> a.insert(0, SPAN('x'))
>>> print(a)
<div><span>x</span></div>
regex_attr = re.compile('\\[([\\w\\-\\:]+)=(.*?)\\]')
regex_class = re.compile('\\.([\\w\\-]+)')
regex_id = re.compile('#([\\w\\-]+)')
regex_tag = re.compile('^[\\w\\-\\:]+')
sibling(*args, **kargs)[源代码]

查找与提供的参数列表和属性字典匹配的第一个同级组件;如果找不到任何组件,则查找“无”。

siblings(*args, **kargs)[源代码]

查找与提供的参数列表和属性字典匹配的所有同级组件;如果找不到任何组件,则查找无。

tag = 'div'
update(**kargs)[源代码]

像字典一样更新标签属性

xml()[源代码]

为此组件生成XML。

class gluon.html.EM(*components, **attributes)[源代码]

基类:gluon.html.DIV

tag = 'em'
class gluon.html.EMBED(*components, **attributes)[源代码]

基类:gluon.html.DIV

tag = 'embed/'
class gluon.html.FIELDSET(*components, **attributes)[源代码]

基类:gluon.html.DIV

tag = 'fieldset'
class gluon.html.FORM(*components, **attributes)[源代码]

基类:gluon.html.DIV

实例:

>>> 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>'

表单是用于输入、文本区域、选择和其他帮助者的容器。

形式有一个重要的方法:

form.accepts(request.vars, session)

如果接受表单(并且所有验证器都通过),则form.vars包含接受的vars,否则form.errors包含错误。如果出现错误,表单将被修改为向用户显示错误。

REDIRECT_JS = "window.location='%s';return false"
accepts(request_vars, session=None, formname='default', keepvalues=False, onvalidation=None, hideerror=False, **kwargs)[源代码]

不使用Kwargs,但允许为Form和sqlForm指定相同的接口

add_button(value, url, _class=None)[源代码]
as_dict(flat=False, sanitize=True)[源代码]

EXPERIMENTAL

消毒是幼稚的。它应该捕获任何不安全的值以供客户端检索。

as_json(sanitize=True)[源代码]
as_xml(sanitize=True)[源代码]
as_yaml(sanitize=True)[源代码]
assert_status(status, request_vars)[源代码]
static confirm(text='OK', buttons=None, hidden=None)[源代码]
hidden_fields()[源代码]
process(**kwargs)[源代码]

执行.validate()方法,但返回表单

在控制器中的用法:

# directly on return
def action():
    #some code here
    return dict(form=FORM(...).process(...))

您可以将其与表单、sqlform或基于表单的插件一起使用:

# 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)[源代码]

此函数用于验证表单,您可以使用它而不是直接使用form.accepts。

用法:在控制器中:

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)

这可能会收到一堆参数

onsuccess='flash'-将在response.flash中显示消息“onsuccess”

无-不做任何事情都不能是函数(lambda形式:pass)

onfailure='flash'-将显示消息“onfailure in response.flash”

无-不做任何事情都不能是函数(lambda形式:pass)

onchange='flash'-将显示消息“onchange in response.flash”

无-不做任何事情都不能是函数(lambda形式:pass)

message ou onsuccess message ou onfailure message ou onchange next=成功时重定向到何处。将为表单传递任何其他Kwarg。接受(…)

xml()[源代码]

为此组件生成XML。

class gluon.html.H1(*components, **attributes)[源代码]

基类:gluon.html.DIV

tag = 'h1'
class gluon.html.H2(*components, **attributes)[源代码]

基类:gluon.html.DIV

tag = 'h2'
class gluon.html.H3(*components, **attributes)[源代码]

基类:gluon.html.DIV

tag = 'h3'
class gluon.html.H4(*components, **attributes)[源代码]

基类:gluon.html.DIV

tag = 'h4'
class gluon.html.H5(*components, **attributes)[源代码]

基类:gluon.html.DIV

tag = 'h5'
class gluon.html.H6(*components, **attributes)[源代码]

基类:gluon.html.DIV

tag = 'h6'
class gluon.html.HEAD(*components, **attributes)[源代码]

基类:gluon.html.DIV

tag = 'head'
class gluon.html.HR(*components, **attributes)[源代码]

基类:gluon.html.DIV

tag = 'hr/'
class gluon.html.HTML(*components, **attributes)[源代码]

基类:gluon.html.DIV

有四个预定义的文档类型定义。它们可以在“doctype”参数中指定:

  • “strict”启用严格doctype

  • “transitional”启用transitional doctype(默认)

  • “frameset”启用frameset doctype

  • “html5”启用HTML 5 doctype

  • 任何其他字符串都将被视为用户自己的doctype

“lang”参数指定文档的语言。默认为“en”。

也见 DIV

frameset = b'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">\n'
html5 = b'<!DOCTYPE HTML>\n'
strict = b'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">\n'
tag = b'html'
transitional = b'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">\n'
xml()[源代码]

为此组件生成XML。

class gluon.html.I(*components, **attributes)[源代码]

基类:gluon.html.DIV

tag = 'i'
class gluon.html.IFRAME(*components, **attributes)[源代码]

基类:gluon.html.DIV

tag = 'iframe'
class gluon.html.IMG(*components, **attributes)[源代码]

基类:gluon.html.DIV

tag = 'img/'
class gluon.html.INPUT(*components, **attributes)[源代码]

基类:gluon.html.DIV

输入组件

采用两个特殊属性值=并要求为。

参数
  • value -- 用于传递输入字段的初始值。值与_值不同,因为它也适用于复选框、收音机、文本区域和选择/选项。对于复选框,值应为“”或“on”。对于收音机或选择/选项,值应为选中/选定项目的值。

  • requires -- 应该是none,或者字段值的验证器或验证器列表。

实例:

>>> 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/'
xml()[源代码]

为此组件生成XML。

class gluon.html.LABEL(*components, **attributes)[源代码]

基类:gluon.html.DIV

tag = 'label'
class gluon.html.LEGEND(*components, **attributes)[源代码]

基类:gluon.html.DIV

tag = 'legend'
class gluon.html.LI(*components, **attributes)[源代码]

基类:gluon.html.DIV

tag = 'li'

基类:gluon.html.DIV

tag = 'link/'
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)[源代码]

基类:gluon.html.XmlComponent

文档:http://web2py.com/examples/static/markmin.html

flatten()[源代码]
xml()[源代码]
class gluon.html.MENU(data, **args)[源代码]

基类:gluon.html.DIV

用于生成菜单

参数
  • _class -- 默认为“web2py menu web2py menu vertical”

  • ul_class -- 默认为“web2py menu vertical”

  • li_class -- 默认为“web2py menu expand”

  • li_first -- 默认为“web2py menu first”

  • li_last -- 默认为“web2py menu last”

用途:

menu = MENU([['name', False, URL(...), [submenu]], ...])
{{=menu}}
serialize(data, level=0)[源代码]
serialize_mobile(data, select=None, prefix='')[源代码]
tag = 'ul'
xml()[源代码]

为此组件生成XML。

class gluon.html.META(*components, **attributes)[源代码]

基类:gluon.html.DIV

tag = 'meta/'
class gluon.html.OBJECT(*components, **attributes)[源代码]

基类:gluon.html.DIV

tag = 'object'
class gluon.html.OL(*components, **attributes)[源代码]

基类:gluon.html.UL

tag = 'ol'
class gluon.html.OPTGROUP(*components, **attributes)[源代码]

基类:gluon.html.DIV

tag = 'optgroup'
class gluon.html.OPTION(*components, **attributes)[源代码]

基类:gluon.html.DIV

tag = 'option'
class gluon.html.P(*components, **attributes)[源代码]

基类:gluon.html.DIV

将取代 \n 通过 <br /> 如果 cr2br 提供了属性。

也见 DIV

tag = 'p'
xml()[源代码]

为此组件生成XML。

class gluon.html.PRE(*components, **attributes)[源代码]

基类:gluon.html.DIV

tag = 'pre'
class gluon.html.SCRIPT(*components, **attributes)[源代码]

基类:gluon.html.DIV

tag = b'script'
tagname = b'script'
xml()[源代码]

为此组件生成XML。

class gluon.html.SELECT(*components, **attributes)[源代码]

基类:gluon.html.INPUT

实例:

>>> 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)[源代码]

基类:gluon.html.DIV

tag = 'span'
class gluon.html.STRONG(*components, **attributes)[源代码]

基类:gluon.html.DIV

tag = 'strong'
class gluon.html.STYLE(*components, **attributes)[源代码]

基类:gluon.html.DIV

tag = 'style'
tagname = b'style'
xml()[源代码]

为此组件生成XML。

class gluon.html.TABLE(*components, **attributes)[源代码]

基类:gluon.html.DIV

表组件。

如果子组件不是tr/tbody/thead/tfoot组件,它们将被包装在tr中。

tag = 'table'
class gluon.html.TBODY(*components, **attributes)[源代码]

基类:gluon.html.DIV

tag = 'tbody'
class gluon.html.TD(*components, **attributes)[源代码]

基类:gluon.html.DIV

tag = 'td'
class gluon.html.TEXTAREA(*components, **attributes)[源代码]

基类:gluon.html.INPUT

实例:

TEXTAREA(_name='sometext', value='blah ' * 100, requires=IS_NOT_EMPTY())

“blah blah…”将是文本区域字段的内容。

tag = 'textarea'
class gluon.html.TFOOT(*components, **attributes)[源代码]

基类:gluon.html.DIV

tag = 'tfoot'
class gluon.html.TH(*components, **attributes)[源代码]

基类:gluon.html.DIV

tag = 'th'
class gluon.html.THEAD(*components, **attributes)[源代码]

基类:gluon.html.DIV

tag = 'thead'
class gluon.html.TITLE(*components, **attributes)[源代码]

基类:gluon.html.DIV

tag = 'title'
class gluon.html.TR(*components, **attributes)[源代码]

基类:gluon.html.DIV

TR成分。

如果子组件不是TD/TH组件,它们将被包装在TD中。

tag = 'tr'
class gluon.html.TT(*components, **attributes)[源代码]

基类:gluon.html.DIV

tag = 'tt'
class gluon.html.UL(*components, **attributes)[源代码]

基类:gluon.html.DIV

UL组件

如果子组件不是li组件,它们将被包装在li中

tag = 'ul'
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, hash_extension=True)[源代码]

生成与应用程序A、控制器C和函数F对应的URL'/a/c/f'。

更典型的用法是:

URL(索引)

它为当前应用程序和控制器中的索引函数生成一个URL。

参数
  • a -- 应用程序(如果给定r,则默认为当前)

  • c -- 控制器(如果给定R,则默认为电流)

  • f -- 函数(如果给定r,则默认为当前值)

  • r -- 请求(可选)

  • args -- 任何参数(可选)。其他“路径”元素

  • vars -- 任何变量(可选)。查询字符串元素

  • anchor -- Anchorname,无(可选)

  • extension -- 强制延长

  • hmac_key -- 生成HMAC签名时使用的密钥(可选)

  • hash_vars -- 在我们的HMAC签名中要包括哪些var,真(默认)-哈希所有var,假-哈希所有var,无一个var,iterable-仅哈希包含的var [“KE1”、“KEY2”]

  • salt -- 盐散列与这个字符串

  • user_signature -- 自动对URL进行签名,以便只有用户可以访问该URL(与一起使用 URL.verifyauth.requires_signature()

  • scheme -- URI方案(true、“http”或“https”等);强制绝对URL(可选)

  • host -- 使用主机强制绝对URL的字符串(true表示http_主机)

  • port -- 可选端口号(强制绝对URL)

  • encode_embedded_slash -- 对参数中包含的斜杠字符进行编码

  • url_encode -- 对vars中包含的字符进行编码

引发

SyntaxError -- 当没有可用的应用程序、控制器或函数,或者在生成的URL中找到CRLF时

实例:

>>> 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)[源代码]

基类:gluon.html.DIV

这是HTML助手的XHTML版本。

有三个预定义的文档类型定义。它们可以在“doctype”参数中指定:

  • “strict”启用严格doctype

  • “transitional”启用transitional doctype(默认)

  • “frameset”启用frameset doctype

  • 任何其他字符串都将被视为用户自己的doctype

“lang”参数指定文档和XML文档的语言。默认为“en”。

“xmlns”参数指定XML命名空间。默认为“http://www.w3.org/1999/xhtml”。

也见 DIV

frameset = b'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">\n'
strict = b'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n'
tag = b'html'
transitional = b'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n'
xml()[源代码]

为此组件生成XML。

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']})[源代码]

基类:gluon.html.XmlComponent

使用它来包装包含XML/HTML的字符串,这样模板就不会对其进行转义。

实例:

>>> XML('<h1>Hello</h1>').xml()
'<h1>Hello</h1>'
elements(*args, **kargs)[源代码]

由于该方法的行为存在疑问,因此认为该方法是实验性的,另一种选择可能是 TAG(self.text).elements(*args, **kwargs)

flatten(render=None)[源代码]

返回由XML对象存储的文本 render 功能

xml()[源代码]
gluon.html.embed64(filename=None, file=None, data=None, extension='image/gif')[源代码]

帮助将提供的(二进制)数据编码为base64。

参数
  • filename -- 如果提供,以“rb”模式打开并读取此文件

  • file -- 如果提供,则读取此文件

  • data -- 如果提供,使用提供的数据

gluon.html.xmlescape(data, quote=True)[源代码]

返回所提供数据的转义字符串

参数
  • data -- 要转义的数据

  • quote -- 可选(默认为假)