### 经常使用的内置过滤器
**abs() :返回参数的绝对值。**
```
{{-123 | abs}} -> 123
```
**capitalize(*s*) :首字母转大写**
```
{{ 'airvip'|capitalize }} -> Airvip
```
**upper(s):字母转大写**
```
{{ 'airvip'|upper}} -> AIRVIP
```
**default(value,default_value=u'',boolean=False):若果 value 为空,设置默认值**
```
{{ ''|default('默认值', true) }} -> 默认值
{{ ''|d('默认值', true) }} -> 默认值
```
**escape(s):特殊符号正常显示**
```
{{ '<airvip>'|e }}
-> <airvip>
{{ '<airvip>'|escape }} -> <airvip>
```
**first(seq):返回序列的第一个元素**
```
{{ ['airvip','python','lisy']|first }} -> airvip
```
**join(value,d=u'',attribute=None):将序列根据分割分连接**
```
{{ [1, 2, 3]|join('|') }} -> 1|2|3
```
**first(seq):返回序列的最后一个元素**
```
{{ ['airvip','python','lisy']|last}} -> lisy
```
**round(value, precision=0, method='common')**
```
{{ 42.55|round }} -> 43.0
{{ 42.55|round(1, 'floor') }} -> 42.5
```
**replace(s, old, new, count=None)**
```
{{ "Hello World"|replace("Hello", "Goodbye") }} -> Goodbye World
```
**random(seq)**
```
{{ ['airvip','lisy','python']|random }} -> 随机出现 airvip 或者 lisy 或者 python
```
**length(object)**
```
{{ 'airvip'|length }} -> 6
{{ ['airvip','lisy','python']|count }} -> 3
```
**map()**
```
{{ [{'name':'airvip','age':24},{'name':'python','age':12},{'name':'lisy','age':18}]|map(attribute='name')|join(', ') }}
-> airvip, python, lisy
{{ [{'name':'airvip','age':24},{'name':'python','age':12},{'name':'lisy','age':18}]|map('upper')|join(', ') }}
-> {'NAME': 'AIRVIP', 'AGE': 24}, {'NAME': 'PYTHON', 'AGE': 12}, {'NAME': 'LISY', 'AGE': 18}
```
**reverse(value)**
```
{{ ['airvip','python','lisy']|reverse|join(",") }} -> lisy,python,airvip
```
**sort(value, reverse=False, case_sensitive=False, attribute=None)**
```
{{ ['airvip','python','lisy']|sort|join(",") }} ->airvip,lisy,python
{% for item in [{'name':'airvip','age':24},{'name':'python','age':12},{'name':'lisy','age':18}]|sort(attribute='age') %}
{{item.age}} --- {{item.name}}
{% endfor %}
-> 12 --- python 18 --- lisy 24 --- airvip
```
传送门:[jinja2模板更多使用说明文档](http://docs.jinkan.org/docs/jinja2/templates.html#builtin-filters)