Django - user permissions to certain views?

后端 未结 5 910
夕颜
夕颜 2020-12-14 01:45

From the admin I see that you can allocate permissions to a user or a user group to :allow add, change or delete data from a model.

That is great, but I also need t

5条回答
  •  一生所求
    2020-12-14 02:28

    If you are using Django 1.9+, you should be able to use PermissionRequiredMixin:

    For example:

    from django.contrib.auth.mixins import PermissionRequiredMixin
    
    class MainView(PermissionRequiredMixin, View):
        permission_required = 'my_services.foo_bar'
        ...
    

    This is basically a special case of UserPassesTestMixin, designed specifically to test whether the user has the indicated permission.

提交回复
热议问题