阅读背景:

在html模板里面加python函数(simple_tag与filter)

来源:互联网 
自定义函数
			simple_tag
				a. app下创建templatetags目录
				b. 任意xxoo.py文件
				c. 创建template对象 register
				d. 
					@register.simple_tag
					def func(a1,a2,a3....)
						return "asdfasd"
				e. settings中注册APP
				f. 顶部 {% load xxoo %}
				g. {% 函数名 arg1 arg2 %}
				缺点:
					不能作为if条件
				优点:
					参数任意
			filter
				a. app下创建templatetags目录
				b. 任意xxoo.py文件
				c. 创建template对象 register
				d. 
					@register.filter
					def func(a1,a2)
						return "asdfasd"
				e. settings中注册APP
				f. 顶部 {% load xxoo %}
				g. {{ 参数1|函数名:"参数二,参数三" }} {{ 参数1|函数名:数字 }}
				缺点:
					最多两个参数,不能加空格
				优点:
					能作为if条件
自定义函数
			simple_tag
				a. app下创建templateta



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: