.
是我的项目根目录,其中manage.py
驻留。我有一个基地模板./templates/base.html
。我在./app/templatetags/mytags.py
如何在base.html中使用自定义模板标记
from django import template
register = template.Library()
@register.unread_tag
def get_unread(user):
return user.notification_set.filter(viewed=False).count()
如何使这种标签可用于base.html文件,使所有应用程序级的模板继承自定义模板标签。
您是否尝试将'{%load mytags%}'放到'base.html'的顶部? – alecxe
{%load mytags%}给我''Library'对象没有属性'unread_tag'' – yayu