Django staff member required

         ·     

Here is a simple decorator that isn’t mentioned properly in the Django documentation.

[cc lang=“python”]@staff_member_required[/cc]

It basically checks to see if the user is logged in and has is_staff before allowing a user access to the view. Use like you would the normal

@login_required decorator.

[cc lang=“python”]

from django.shortcuts import render_to_response

from django.template.context import RequestContext

from django.contrib.admin.views.decorators import staff_member_required

@staff_member_required

def my_view(request):

return render_to_response(‘page.html’,

context_instance=RequestContext(request))

[/cc]

comments powered by Disqus