我查找了DJANGO模板的过滤器,好像指定字符串包含指定关-键字符的过滤器没有呢,
没有硬着头-皮,按网上其它人的作法,写了一个,成功了。。。:)
参考URL:
http://liuzhijun.iteye.com/blog/1884630
http://www.xxx.com/html/2013/pythonweb_1017/588.html
templatetags目录下的deploy_filter.py文件如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
#!/usr/bin/env python
# coding:utf-8
from
django
import
template
register
=
template.Library()
@register
.
filter
(name
=
'str_contain'
)
def
str_contain_filter(value, arg
=
None
):
'''查看指定字符串是否包含关-键字'''
print
arg, value,
'#############'
if
arg
in
str
(value):
return
True
else
:
return
False
# register.filter('str_contain', str_contain_filter)
|
在模板网页里载入方法如下:
1
|
{% load deploy_filter %}
|
使用如下:
1
2
3
4
5
|
{% if item.app_name|str_contain:"SQL" %}
have sql hahaha
{% else %}
have not sql hahaha
{% endif%}
|