Loading

templatetags使用

1.filter示例

from django.template import Library

register = Library()


@register.filter
def has_permission(request, route_name):
    is_super = request.user_dict['is_super']
    if is_super:
        return True

    if route_name in request.permission_dict:
        return True

    return False

2.inclusion_tag示例

from django.template import Library

register = Library()


@register.inclusion_tag("rbac/include/menu.html")
def menu(request):
	menu_dict = {}
	
	return {"menu_dict": menu_dict}
posted @ 2024-09-08 11:00  一只大学生  阅读(6)  评论(0编辑  收藏  举报