171👍
This decorator already exists as
from django.contrib.admin.views.decorators import staff_member_required
@staff_member_required
Trunk:
http://code.djangoproject.com/browser/django/trunk/django/contrib/admin/views/decorators.py
27👍
For Class Based Views, you can decorate the view class’s dispatch method like this:
from django.contrib.admin.views.decorators import staff_member_required
from django.utils.decorators import method_decorator
@method_decorator(staff_member_required, name='dispatch')
class ExampleTemplateView(TemplateView):
...
- [Django]-What does this Django regular expression mean? `?P`
- [Django]-Malformed Packet: Django admin nested form can't submit, connection was reset
- [Django]-How do I add a custom column with a hyperlink in the django admin interface?
11👍
This style of decorator function is used with a parameterised decorator – eg when you do:
@staffonly(my_arguments)
def function(request):
blah
If you’re not actually calling the outer function, ie you’re using it like this:
@staffonly
def function(request):
You will get odd results, as the function object will be passed to the wrong one of the nested functions in the decorator.
- [Django]-Django Multiple Authentication Backend for one project
- [Django]-How to make a PATCH request using DJANGO REST framework
- [Django]-Django switching, for a block of code, switch the language so translations are done in one language
0👍
I use Your Decorator and I face only one error:-
'bool' object is not callable
this error comes from here if u.is_authenticated() and u.is_staff:
I change u.is_authenticated()
to u.is_authenticated
and it nicely works for me
- [Django]-Django 1.8 KeyError: 'manager' on relationship
- [Django]-Django Rest Framework – APIView Pagination
- [Django]-Access-Control-Allow-Origin in Django app
Source:stackexchange.com