Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Django可以在应用程序而不是模型上设置权限吗_Django_Python 2.7 - Fatal编程技术网

Django可以在应用程序而不是模型上设置权限吗

Django可以在应用程序而不是模型上设置权限吗,django,python-2.7,Django,Python 2.7,我想有权控制我的项目。一些用户可以看到某些应用程序的条目,而其他用户则看不到。我想在应用程序而不是模型上设置权限,我已经搜索过了,但只找到了如何在模型上设置权限。因此,我想知道如何设置应用程序的权限。您可以使用装饰程序有选择地允许用户访问页面 制作此装饰器 def filter_users(func): def checker(request,*args,**kwargs): if some_condition: #This condition will tell

我想有权控制我的项目。一些用户可以看到某些应用程序的条目,而其他用户则看不到。我想在应用程序而不是模型上设置权限,我已经搜索过了,但只找到了如何在模型上设置权限。因此,我想知道如何设置应用程序的权限。

您可以使用装饰程序有选择地允许用户访问页面
制作此装饰器

def filter_users(func):

    def checker(request,*args,**kwargs):
         if some_condition: #This condition will tell you whether to allow this perticular user
             return func(request,*args,**kwargs)
         else:
             return render('invalid.html') #return a page telling the user that he is not allowed

    return checker
现在,只需将此装饰程序应用于所有要阻止“某些”用户访问的视图

例:

现在只有允许的用户才能看到视图,其余所有用户都将获得无效页面


您可以将此装饰器应用于要限制访问的特定应用程序的所有视图

使用自定义装饰器加载项URL这是否适用于django管理站点?还是其他的场景?你认为什么是“应用程序的权限”?用户可以有权限执行的操作通常是创建/读取/更新/删除操作,这些操作是在模型上执行的。您是否研究过使用权限组,这是默认django auth应用程序的一部分。在我的情况下,我希望一些用户可以看到菜单中某些应用程序的条目,而其他用户则不能。
@filter_users
def some_view(request):
    #Do Something...