1.filter示例
from django.template import Libraryregister = Library()@register.filter
def has_permission(request, route_name):is_super = request.user_dict['is_super']if is_super:return Trueif route_name in request.permission_dict:return Truereturn False
2.inclusion_tag示例
from django.template import Libraryregister = Library()@register.inclusion_tag("rbac/include/menu.html")
def menu(request):menu_dict = {}return {"menu_dict": menu_dict}