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}