小编Sli*_*dal的帖子

Django 1.10.1'my_templatetag'不是注册的标签库.必须是以下之一:

我想要一个自定义的菜单,取决于您所属的组.我使用Django 1.10.1,allauth等.当我试图制作我的模板标签失败时,它说:¨

TemplateSyntaxError at /
'my_templatetag' is not a registered tag library. Must be one of:
account
account_tags
admin_list
admin_modify
admin_static
admin_urls
cache
i18n
l10n
log
socialaccount
socialaccount_tags
static
staticfiles
tz
Run Code Online (Sandbox Code Playgroud)

'my_templatetag.py'看起来像这样:

from django import template
from django.contrib.auth.models import Group


register = template.Library()

@register.filter(name='has_group')
def has_group(user, group_name):
    group =  Group.objects.get(name=group_name)
    return group in user.groups.all()
Run Code Online (Sandbox Code Playgroud)

和我的.html文件中出现错误,说,

{%  load my_templatetag %}
Run Code Online (Sandbox Code Playgroud)

我试图重启服务器数百万次,我也尝试更改所有名称,该应用程序是settings.py中的INSTALLED_APPS的一部分.我究竟做错了什么?

django templatetags django-allauth

56
推荐指数
7
解决办法
4万
查看次数

标签 统计

django ×1

django-allauth ×1

templatetags ×1