我使用django 1.7.8并检查doc:https://docs.djangoproject.com/en/1.7/howto/custom-template-tags/#assignment-tags。我写了一个分配标签来检查权限。在/templatetags/folder_perms.py
from django import template
register = template.Library()
@register.assignment_tag(takes_context=True)
def get_folder_permission(context, folder):
request = context['request']
return folder.has_read_permission(request)
我在我的模板中使用它如下:
...
{% load folder_perms_tags %}
...
{% get_folder_permission 'object.folder' as curr_perm %}
{{ curr_perm }}
...
当我渲染模板时,我收到错误
'get_folder_permission' received too many positional arguments
答案 0 :(得分:1)
哇,我很蠢,加载了错误的模板标签
只需改变
{% load folder_perms_tags %}
到
{% load folder_perms %}