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)
精彩评论