Use staff_member_required decorator, but without being redirected to the admin interface?

When I try to use staff_view, I get redirected in the admin authentication interface.

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

    @staff_member_required
    def staff_view(request..):
        ...

How can I make a custom login, and not getting redirected in the default admin login interface?

Answers


You can use Django's user_passes_test decorator:

from django.contrib.auth.decorators import user_passes_test

@user_passes_test(lambda u:u.is_staff, login_url=reverse_lazy('foo'))
def staff_view(request..):
    ...

It's worth pointing out that staff_member_required is a wrapper around user_passes_test (see source code) and it also accepts a login_url parameter, so you could do:

@staff_member_required(login_url=example_url)
def staff_view(request..):
    ...

Need Your Help

Jackson 2.0 with Spring 3.1

java json spring spring-mvc jackson

Is Spring MVC 3.1 compatible with Jackson 2.0? Will Spring MVC's automatic detection of Jackson on the classpath, and delegation to Jackson for requests with a JSON content-type still work?

Image processing library for Android?

android image-processing

A friend who works in the medical profession asked me to try and write a small application for Android that could take a picture, analyze it in terms of colors and size so we know how it evolved si...