# 在某个app下新建一个templatetags 文件夹
# 需要确定在settings.py 中对该app 进行了注册
# 在templatetags中建立一个.py文件
from django import template
register = template.Library()
from ..models import Virus
@register.simple_tag(name='virus')
def virus():
return Virus.objects.count()
# .py 文件夹是{%load xxx %} 时候需要使用的对象
# name 对应是使用的时候写的对象 {% xxx %}
# 可以不指定name,函数名即为默认的name
django自定义templatetags
最新推荐文章于 2024-01-29 18:31:14 发布