restricting views to staff users in django
Sep
02
1
0
Hopefully you've already found the login_required decorator for Django views, which make it incredibly simple to integrate authentication into the site.
One thing that's not documented well is there's another decorator @staff_member_required. This works the same way @login_required does except it restricts access to users who are both authenticated and has staff status set in their settings.
This comes in handy when extending the admin or writing custom moderation applications.
You can do something similar to:
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 view(request): ... return render_to_response('template.html', context_instance=RequestContext(request))