Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 309279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:43:38+00:00 2026-05-12T07:43:38+00:00

I can’t figure out why the permission required decorator isn’t working. I would like

  • 0

I can’t figure out why the permission required decorator isn’t working. I would like to allow access to a view only for staff members. I have tried

@permission_required('request.user.is_staff',login_url="../admin")
def series_info(request):
  ...

and also

@permission_required('user.is_staff',login_url="../admin")
def series_info(request):
  ...

As the superuser, I can access the view, but any users I create as staff can’t access it and are redirected to the login url page. I tested the login_required decorator and that works fine.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T07:43:39+00:00Added an answer on May 12, 2026 at 7:43 am

    permission_required() must be passed a permission name, not a Python expression in a string. Try this instead:

    from contrib.auth.decorators import user_passes_test
    def staff_required(login_url=None):
        return user_passes_test(lambda u: u.is_staff, login_url=login_url)
    
    @staff_required(login_url="../admin")
    def series_info(request)
    ...
    

    Thanks. That does work. Do you have an
    example of how to use
    permission_required? From the
    documentation
    docs.djangoproject.com/en/1.0/… and
    djangobook.com/en/2.0/chapter14 I
    thought what I had should work.

    Re-read the links you posted; permission_required() will test if a user has been granted a particular permission. It does not test the attributes of the user object.

    From http://www.djangobook.com/en/2.0/chapter14/:

    def vote(request):
        if request.user.is_authenticated() and request.user.has_perm('polls.can_vote'):
            # vote here
        else:
            return HttpResponse("You can't vote in this poll.")
    
       #
       #
     # # #
      ###
       #
    
    def user_can_vote(user):
        return user.is_authenticated() and user.has_perm("polls.can_vote")
    
    @user_passes_test(user_can_vote, login_url="/login/")
    def vote(request):
        # vote here
    
       #
       #
     # # #
      ###
       #
    
    from django.contrib.auth.decorators import permission_required
    
    @permission_required('polls.can_vote', login_url="/login/")
    def vote(request):
        # vote here
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Can someone maybe tell me why this is not working? I have used echo
Can some one confirm me that only one UIWindow instance is possible in any
Can someone please explain how this code is working for me? I don't understand
Can I access my SkyDrive using a permanent access token? Basically, I want to
Can any one help me in sorting this out in sed/awk/perl Input file Start
Can someone access the database files and/or other files of my app stores in
Can anyone tell me how an IDE like NetBeans or any for that matter
Can someone help me? I am trying to do something like the following: #include
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.