内置过滤器清单¶

abs(number)¶

Return the absolute value of the argument.

attr(obj, name)¶

Get an attribute of an object. foo|attr("bar") works like

foo["bar"] just that always an attribute is returned and items are not

looked up.

batch(value, linecount, fill_with=None)¶

A filter that batches items. It works pretty much like slice

just the other way round. It returns a list of lists with the

given number of items. If you provide a second parameter this

is used to fill up missing items. See this example:

{%- for row in items|batch(3, ' ') %}

{%- for column in row %}

{{ column }}

{%- endfor %}

{%- endfor %}

capitalize(s)¶

Capitalize a value. The first character will be uppercase, all others

lowercase.

center(value, width=80)¶

Centers the value in a field of a given width.

default(value, default_value=u'', boolean=False)¶

If the value is undefined it will return the passed default value,

otherwise the value of the variable:

{{ my_variable|default('my_variable is not defined') }}

This will output the value of my_variable if the variable was

defined, otherwise 'my_variable is not defined'. If you want

to use default with variables that evaluate to false you have to

set the second parameter to true:

{{ ''|default('the string was empty', true) }}

Aliases :d

dictsort(value, case_sensitive=False, by='key')¶

Sort a dict and yield (key, value) pairs. Because python dicts are

unsorted you may want to use this function to order them by either

key or value:

{% for item in mydict|dictsort %}

sort the dict by key, case insensitive

{% for item in mydict|dictsort(true) %}

sort the dict by key, case sensitive

{% for item in mydict|dictsort(false, 'value') %}

sort the dict by key, case insensitive, sorted

normally and ordered by value.

escape(s)¶

Convert the characters &, , ‘, and ” in string s to HTML-safe

sequences. Use this if you need to display text that might contain

such characters in HTML. Marks return value as markup string.

Aliases :e

filesizeformat(value, binary=False)¶

Format the value like a ‘human-readable’ file size (i.e. 13 kB,

4.1 MB, 102 Bytes, etc). Per default decimal prefixes are used (Mega,

Giga, etc.), if the second parameter is set to True the binary

prefixes are used (Mebi, Gibi).

first(seq)¶

Return the first item of a sequence.

float(value, default=0.0)¶

Convert the value into a floating point number. If the

conversion doesn’t work it will return 0.0. You can

override this default using the first parameter.

forceescape(value)¶

Enforce HTML escaping. This will probably double escape variables.

format(value, *args, **kwargs)¶

Apply python string formatting on an object:

{{ "%s - %s"|format("Hello?", "Foo!") }}

-> Hello? - Foo!

groupby(value, attribute)¶

Group a sequence of objects by a common attribute.

If you for example have a list of dicts or objects that represent persons

with gender, first_name and last_name attributes and you want to

group all users by genders you can do something like the following

snippet:

{% for group in persons|groupby('gender') %}

{{ group.grouper }}

{% for person in group.list %}

{{ person.first_name }} {{ person.last_name }}

{% endfor %}

{% endfor %}

Additionally it’s possible to use tuple unpacking for the grouper and

list:

{% for grouper, list in persons|groupby('gender') %}

...

{% endfor %}

As you can see the item we’re grouping by is stored in the grouper

attribute and the list contains all the objects that have this grouper

in common.

Changed in version 2.6:It’s now possible to use dotted notation to group by the child

attribute of another attribute.

indent(s, width=4, indentfirst=False)¶

Return a copy of the passed string, each line indented by

4 spaces. The first line is not indented. If you want to

change the number of spaces or indent the first line too

you can pass additional parameters to the filter:

{{ mytext|indent(2, true) }}

indent by two spaces and indent the first line too.

int(value, default=0)¶

Convert the value into an integer. If the

conversion doesn’t work it will return 0. You can

override this default using the first parameter.

join(value, d=u'', attribute=None)¶

Return a string which is the concatenation of the strings in the

sequence. The separator between elements is an empty string per

default, you can define it with the optional parameter:

{{ [1, 2, 3]|join('|') }}

-> 1|2|3

{{ [1, 2, 3]|join }}

-> 123

It is also possible to join certain attributes of an object:

{{ users|join(', ', attribute='username') }}

New in version 2.6:The attribute parameter was added.

last(seq)¶

Return the last item of a sequence.

length(object)¶

Return the number of items of a sequence or mapping.

Aliases :count

list(value)¶

Convert the value into a list. If it was a string the returned list

will be a list of characters.

lower(s)¶

Convert a value to lowercase.

map()¶

Applies a filter on a sequence of objects or looks up an attribute.

This is useful when dealing with lists of objects but you are really

only interested in a certain value of it.

The basic usage is mapping on an attribute. Imagine you have a list

of users but you are only interested in a list of usernames:

Users on this page:{{ users|map(attribute='username')|join(', ') }}

Alternatively you can let it invoke a filter by passing the name of the

filter and the arguments afterwards. A good example would be applying a

text conversion filter on a sequence:

Users on this page:{{ titles|map('lower')|join(', ') }}

New in version 2.7.

pprint(value, verbose=False)¶

Pretty print a variable. Useful for debugging.

With Jinja 1.2 onwards you can pass it a parameter. If this parameter

is truthy the output will be more verbose (this requires pretty)

random(seq)¶

Return a random item from the sequence.

reject()¶

Filters a sequence of objects by appying a test to either the object

or the attribute and rejecting the ones with the test succeeding.

Example usage:

{{ numbers|reject("odd") }}

New in version 2.7.

rejectattr()¶

Filters a sequence of objects by appying a test to either the object

or the attribute and rejecting the ones with the test succeeding.

{{ users|rejectattr("is_active") }}

{{ users|rejectattr("email", "none") }}

New in version 2.7.

replace(s, old, new, count=None)¶

Return a copy of the value with all occurrences of a substring

replaced with a new one. The first argument is the substring

that should be replaced, the second is the replacement string.

If the optional third argument count is given, only the first

count occurrences are replaced:

{{ "Hello World"|replace("Hello", "Goodbye") }}

-> Goodbye World

{{ "aaaaargh"|replace("a", "d'oh, ", 2) }}

-> d'oh, d'oh, aaargh

reverse(value)¶

Reverse the object or return an iterator the iterates over it the other

way round.

round(value, precision=0, method='common')¶

Round the number to a given precision. The first

parameter specifies the precision (default is 0), the

second the rounding method:

'common' rounds either up or down

'ceil' always rounds up

'floor' always rounds down

If you don’t specify a method 'common' is used.

{{ 42.55|round }}

-> 43.0

{{ 42.55|round(1, 'floor') }}

-> 42.5

Note that even if rounded to 0 precision, a float is returned. If

you need a real integer, pipe it through int:

{{ 42.55|round|int }}

-> 43

safe(value)¶

Mark the value as safe which means that in an environment with automatic

escaping enabled this variable will not be escaped.

select()¶

Filters a sequence of objects by appying a test to either the object

or the attribute and only selecting the ones with the test succeeding.

Example usage:

{{ numbers|select("odd") }}

New in version 2.7.

selectattr()¶

Filters a sequence of objects by appying a test to either the object

or the attribute and only selecting the ones with the test succeeding.

Example usage:

{{ users|selectattr("is_active") }}

{{ users|selectattr("email", "none") }}

New in version 2.7.

slice(value, slices, fill_with=None)¶

Slice an iterator and return a list of lists containing

those items. Useful if you want to create a div containing

three ul tags that represent columns:

{%- for column in items|slice(3) %}

{%- for item in column %}

{{ item }}

{%- endfor %}

{%- endfor %}

If you pass it a second argument it’s used to fill missing

values on the last iteration.

sort(value, reverse=False, case_sensitive=False, attribute=None)¶

Sort an iterable. Per default it sorts ascending, if you pass it

true as first argument it will reverse the sorting.

If the iterable is made of strings the third parameter can be used to

control the case sensitiveness of the comparison which is disabled by

default.

{% for item in iterable|sort %}

...

{% endfor %}

It is also possible to sort by an attribute (for example to sort

by the date of an object) by specifying the attribute parameter:

{% for item in iterable|sort(attribute='date') %}

...

{% endfor %}

Changed in version 2.6:The attribute parameter was added.

string(object)¶

Make a string unicode if it isn’t already. That way a markup

string is not converted back to unicode.

striptags(value)¶

Strip SGML/XML tags and replace adjacent whitespace by one space.

sum(iterable, attribute=None, start=0)¶

Returns the sum of a sequence of numbers plus the value of parameter

‘start’ (which defaults to 0). When the sequence is empty it returns

start.

It is also possible to sum up only certain attributes:

Total:{{ items|sum(attribute='price') }}

Changed in version 2.6:The attribute parameter was added to allow suming up over

attributes. Also the start parameter was moved on to the right.

title(s)¶

Return a titlecased version of the value. I.e. words will start with

uppercase letters, all remaining characters are lowercase.

trim(value)¶

Strip leading and trailing whitespace.

truncate(s, length=255, killwords=False, end='...')¶

Return a truncated copy of the string. The length is specified

with the first parameter which defaults to 255. If the second

parameter is true the filter will cut the text at length. Otherwise

it will discard the last word. If the text was in fact

truncated it will append an ellipsis sign ("..."). If you want a

different ellipsis sign than "..." you can specify it using the

third parameter.

{{ "foo bar"|truncate(5) }}

-> "foo ..."

{{ "foo bar"|truncate(5, True) }}

-> "foo b..."

upper(s)¶

Convert a value to uppercase.

urlencode(value)¶

Escape strings for use in URLs (uses UTF-8 encoding). It accepts both

dictionaries and regular strings as well as pairwise iterables.

New in version 2.7.

urlize(value, trim_url_limit=None, nofollow=False)¶

Converts URLs in plain text into clickable links.

If you pass the filter an additional integer it will shorten the urls

to that number. Also a third argument exists that makes the urls

“nofollow”:

{{ mytext|urlize(40, true) }}

links are shortened to 40 chars and defined with rel="nofollow"

wordcount(s)¶

Count the words in that string.

wordwrap(s, width=79, break_long_words=True, wrapstring=None)¶

Return a copy of the string passed to the filter wrapped after

79 characters. You can override this default using the first

parameter. If you set the second parameter to false Jinja will not

split words apart if they are longer than width. By default, the newlines

will be the default newlines for the environment, but this can be changed

using the wrapstring keyword argument.

New in version 2.7:Added support for the wrapstring parameter.

xmlattr(d, autospace=True)¶

Create an SGML/XML attribute string based on the items in a dict.

All values that are neither none nor undefined are automatically

escaped:

'id': 'list-%d'|format(variable)}|xmlattr }}>

...

Results in something like this:

...

As you can see it automatically prepends a space in front of the item

if the filter returned something unless the second parameter is false.

python网页设计模板_模板设计者文档相关推荐

  1. HTML5汽车网页设计成品_学生DW汽车静态网页设计代做_web课程设计网页制作_宽屏大气汽车自驾游网站模板html源码...

    HTML5汽车网页设计成品_学生DW汽车静态网页设计代做_web课程设计网页制作_宽屏大气汽车自驾游网站模板html源码 临近期末, 你还在为HTML网页设计结课作业,老师的作业要求感到头大?HTML ...

  2. HTML5汽车网页设计成品_学生DW汽车静态网页设计代做_web课程设计网页制作_宽屏大气汽车自驾游网站模板html源码

    HTML5汽车网页设计成品_学生DW汽车静态网页设计代做_web课程设计网页制作_宽屏大气汽车自驾游网站模板html源码 临近期末, 你还在为HTML网页设计结课作业,老师的作业要求感到头大?HTML ...

  3. DIV+CSS进行布局 HTML+CSS+JS大作业——汽车销售网站模板(7页) html网页设计期末大作业_网页设计平时作业模板下载

    HTML+CSS+JS大作业--汽车销售网站模板(7页) html网页设计期末大作业_网页设计平时作业模板下载 常见网页设计作业题材有 个人. 美食. 公司. 学校. 旅游. 电商. 宠物. 电器. ...

  4. HTML+CSS+JS大作业——汽车销售网站模板(7页) html网页设计期末大作业_网页设计平时作业模板下载

    HTML+CSS+JS大作业--汽车销售网站模板(7页) html网页设计期末大作业_网页设计平时作业模板下载 常见网页设计作业题材有 个人. 美食. 公司. 学校. 旅游. 电商. 宠物. 电器. ...

  5. div+css静态网页设计——迪斯尼公主滚动特效(7页) HTML5网页设计成品_学生DW静态网页设计代做_web课程设计网页制作

    HTML5期末大作业:电影网站设计--迪斯尼公主滚动特效(7页) HTML5网页设计成品_学生DW静态网页设计代做_web课程设计网页制作 常见网页设计作业题材有 个人. 美食. 公司. 学校. 旅游 ...

  6. 期末作业成品代码——红色的婚庆(18页) HTML5网页设计成品_学生DW静态网页设计代做_web课程设计网页制作

    HTML5期末大作业:婚庆网站设计--红色的婚庆(18页) HTML5网页设计成品_学生DW静态网页设计代做_web课程设计网页制作 常见网页设计作业题材有 个人. 美食. 公司. 学校. 旅游. 电 ...

  7. 在Qt中使用已有模板创建新Word文档

    简 在这篇帖子中我将详细讲述如何在Qt环境下使用已有Word模板文件创建新的文档,并对模板文档内容填充.目前,我只对替换文字和对表格进行操作进行了介绍,如何在文档插入图片未在本文中提及. 述 开发环境 ...

  8. HTML5期末大作业:鲜花超市网站设计——鲜花超市(4页) HTML+CSS+JavaScript HTML5网页设计成品_学生DW静态网页设计代做_web课程设计网页制作

    HTML5期末大作业:鲜花超市网站设计--鲜花超市(4页) HTML+CSS+JavaScript HTML5网页设计成品_学生DW静态网页设计代做_web课程设计网页制作 作品介绍 1.网页作品简介 ...

  9. word模板生成word报表文档

    主要功能为根据word模板生成word报表文档,注意引用Interop.Word.dll; 首先要生成word程序对象 Word.Application app = new Word.Applicat ...

  10. Freemarker - 根据模板动态生成word文档

    文章目录 Freemarker 根据模板动态生成word文档 Freemarker 介绍: Freemarker 使用: freemarker加载模板目录的方法 参考资料 Freemarker 根据模 ...

最新文章

  1. 自媒体敏感词大全_让新媒体小编头疼的敏感词与错别字
  2. rhel6.0配置rsyslog传送日志到远程主机
  3. 机器学习笔记(十二)计算学习理论
  4. 实例入手Vue-Route给引用组件传值以及实现组件重用
  5. insert时调用本身字段_MySQL RC级别下并发insert锁超时问题 - 案例验证
  6. 工作204:进行输入成功后验证
  7. (翻译).NET应用架构
  8. 2345天气王怎么查看历史天气 2345天气王如何查看历史天气
  9. Tomcat的三种会话保持
  10. Java反编译插件Jdclipse导致Eclipse 3.7.2启动崩溃的解决方法
  11. 统计自然语言处理---信息论基础
  12. [原创]:善用佳软(三)
  13. icns文件怎么打开_Mac快速生成icns图标文件 | kTWO-个人博客
  14. 7年老Android一次操蛋的面试经历,讲的明明白白!
  15. python pyecharts绘制旭日图Sunburst
  16. python的request发请求报500原因
  17. 虎从风跃,龙借云行--神行者Wi10无线移动硬盘开启WIFI无线存储共享新时代_MID论坛_太平洋电脑网产品论坛...
  18. 20 个 JavaScript 单行代码杀手锏
  19. MYSQL创建课程表course_MySQL简单案例之创建学生表、课程表和选课表
  20. fpt指的是什么_ftp是什么意思

热门文章

  1. App端安全性加密策略
  2. 大众迈腾车发动机偶尔无法起动?车主还说,故障好几天才会出现1次,一起来看看怎么回事吧!
  3. java小游戏抽签系统(一)界面搭建
  4. 程序员的真实价值,浅谈职业生涯规划
  5. [推荐]GOOGLE搜索从入门到精通v3.0
  6. opencv--直方图
  7. 企业如何实现对大数据的处理与分析?
  8. GD32F4xx MCU控制I2C EEPROM(AT24C16)记录
  9. 33个优秀的网站底部设计案例欣赏
  10. 纽扣电池的分类和介绍