开发者

how to create a page only can be visited by admin using django

开发者 https://www.devze.com 2022-12-26 17:28 出处:网络
how to do this and has pinax any a开发者_运维知识库pp do this ? thanksDjango provides a decorator for testing a user at the view-level.You can use this to enforce an \"admin-only\" for a given vi

how to do this

and

has pinax any a开发者_运维知识库pp do this ?

thanks


Django provides a decorator for testing a user at the view-level. You can use this to enforce an "admin-only" for a given view.

from django.contrib.auth.decorators import user_passes_test

@user_passes_test(lambda u: u.is_staff)
def my_admin_only_view(request, *args, **kwargs):
    # ...

# could also test for superuser only, or whatever else you like
@user_passes_test(lambda u: u.is_superuser)
0

精彩评论

暂无评论...
验证码 换一张
取 消