开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜