标签:created usr django air lang filter rar type app
关于Django的模板这里有详细介绍
http://www.runoob.com/django/django-template.html
1、在app下创建templatetags的目录,在目录下创建test.py文件
2、test.py内容
1 #!/usr/bin/env python 2 #created by Baird 3 from django import template 4 5 register = template.Library() #注册 6 7 @register.simple_tag() 8 def Custom_add(a,b): 9 return a+b 10 11 @register.filter() 12 def Custom_multiply(a): 13 return a*a
3、simple_tag和filter的使用方式(在template中的html文件中使用)
1 {% load test %} {# 加载 #} 2 <!DOCTYPE html> 3 <html lang="en"> 4 <head> 5 <meta charset="UTF-8"> 6 <title>Title</title> 7 </head> 8 <body> 9 {% Custom_add 1 2 %} {# simple_tag #} 10 {{ 5|Custom_multiply }} {# filter #} 11 </body> 12 </html>
django-自定义过滤器(simple_tag和filter)
标签:created usr django air lang filter rar type app
原文地址:https://www.cnblogs.com/baird/p/9542606.html