- 自定义函数
simple_tag
a. app下创建templatetags目录
b. 任意xxoo.py文件
c. 创建template对象 register
d.

__author__ = 'Administrator'
from django import template
from django.utils.safestring import mark_safe

register = template.Library()
@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条件

 

相关文章:

  • 2022-12-23
  • 2022-01-17
  • 2021-12-26
  • 2021-09-24
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-09
  • 2022-12-23
  • 2021-07-02
  • 2022-12-23
  • 2022-12-23
  • 2021-07-27
  • 2022-12-23
相关资源
相似解决方案