如何在Django中检查用户是否对URL具有权限

时间:2019-03-10 14:55:11

标签: django django-permissions

如何检查用户对Django中URL的权限

我有URL-管理员/用户/用户个人资料

我想检查登录用户是否有权访问该操作吗?

def get_nav_list(context, **kwargs): 
    request = context['request']
    navigation = Navigation.objects.all()
    menus = []
    menu_tree = {}
    for nav in navigation:

        if nav.parent_id is None:
            menus.append(nav.navigation_weight)
            menu_tree[nav.id] = {}
            menu_tree[nav.id]['parent'] = nav
            menu_tree[nav.id]['children'] = {}

    for nav in navigation:
        if nav.parent_id:
            if  check_menu_permissions(nav.navigation_link , request.user):
                menu_tree[nav.parent_id]['children'][nav.id] = nav

关于check_menu_permissions函数的问题

Note: I have build navigation Module like wordpress in django 

0 个答案:

没有答案