Answers for "django permissions model"

4

loginrequiredmixin

from django.contrib.auth.mixins import LoginRequiredMixin

LOGIN_URL = 'your_url'
Posted by: Guest on October-18-2020
1

Django: checking permission on user

from django.contrib.auth.decorators import permission_required

@permission_required('auth.view_user')
def users_list_view(request):
    pass
Posted by: Guest on June-07-2021
0

Django: checking permission on user

from django.core.exceptions import PermissionDenied

def users_list_view(request):
    if not request.user.has_perm('auth.view_user'):
        raise PermissionDenied()
Posted by: Guest on June-07-2021
0

Django: checking permission on user

{% if perms.auth.delete_user %}
<button>Delete user!</button>
{% endif %}
Posted by: Guest on June-07-2021

Python Answers by Framework

Browse Popular Code Answers by Language