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 8514709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:56:41+00:00 2026-06-11T04:56:41+00:00

I have a problem with decorator. I’m trying to write my own decorator with

  • 0

I have a problem with decorator. I’m trying to write my own decorator with optional argument.

This is how its done now:

def CheckPremissions(manager=1):
    def wrap(func):
        def wrapper(request, *args, **kwargs):
            if request.user.is_anonymous():
                return HttpResponseRedirect(reverse('login'))

            logged_user = getRelatedWorker(request.user)

            if (logged_user == None):
                return HttpResponseRedirect('accounts/no_worker_error.html')

            if self.manager != 0:
                try:
                    dzial = Dzial.objects.get(kierownik=logged_user)
                except Dzial.DoesNotExist:
                    isManager = False
                else:
                    isManager = True

                if not isManager:
                    return HttpResponseRedirect('accounts/denied_logged.html')

            return func(request, *args, **kwargs)
        return wrapper
    return wrap

Code is looking good (for me), but when I use a decorator, I’m getting following error:

Environment:

    Request Method: GET
    Request URL: http://127.0.0.1:8080/applications/show

    Django Version: 1.4.1
    Python Version: 2.7.3


Traceback:
    File "/home/marcin/projekt/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
      188.                 response = middleware_method(request, response)
    File "/home/marcin/projekt/lib/python2.7/site-packages/django/middleware/common.py" in process_response
      94.         if response.status_code == 404:

    Exception Type: AttributeError at /applications/show
    Exception Value: 'function' object has no attribute 'status_code'

What am I doing wrong?

  • 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-06-11T04:56:42+00:00Added an answer on June 11, 2026 at 4:56 am

    I suspect you are applying the decorator incorrectly. You need to call it to specify the manager parameter:

    @CheckPremissions()
    def someview(request):
        pass
    

    or to specify it explicitly:

    @CheckPremissions(manager=0)
    def someview(request):
        pass
    

    You have a different problem in your decorator as well; you refer to self.manager in the code:

    if self.manager != 0:
    

    but this is no instance, and there is no self parameter. I think you meant:

    if manager:
    

    (where you can test for the variable to be non-zero by treating it as a boolean). Oh, and you may want to fix the spelling of the decorator; you probably meant CheckPermissions instead. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem using docstrings with decorators. Given the following example: def decorator(f):
Trying out celery for django I ran into a problem with @task decorator. This
I have problem with my query on C, I’m using the oci8 driver. This
I have problem with TableView its empty. In (.h) file: @interface TableViewController : UITableViewController{
I have a problem with aligning my legends in forms, and reading the decorator
I have a problem with the transfer of the variable insurance_mode by the decorator.
I'm trying get to know decorators, and I have a problem with sharing value,
I have an application that's built on top of Eventlet. I'm trying to write
Here is my problem. I am trying to write a small simple game engine
I have problem with http://abfoodpolicy.com/ . In IE 8 and 9 the right sidebar

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.