0

I'm writing a small app. I wish to use a view decorator I found. This here is the snippet, and this is a post describing its usage. I have an Apache server (2.2) running, and Django is up-to-date. I've decorated a view, and when trying to GET it, an AttributeError occurs:

Request Method: GET
Request URL: http://localhost/redb/test/

Django Version: 1.5.1
Python Version: 2.7.5
Installed Applications:
('django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.admin',
 'django.contrib.admindocs',
 'redb_app')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware')

Traceback:
File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in get_response
  187.                 response = middleware_method(request, response)
File "C:\Python27\lib\site-packages\django\middleware\common.py" in process_response
  109.         if response.status_code == 404:

Exception Type: AttributeError at /redb/test/
Exception Value: 'function' object has no attribute 'status_code'

This is how I'm using it:

@logged_in_or_basicauth
def test_handler(request):
    return HttpResponse("Test!")

Thanks!

1 Answer 1

1

The decorator takes an argument, so you must call the decorator, even if you do not provide the argument realm and let it default to "".

@logged_in_or_basicauth()
def test_handler(request):
    return HttpResponse("Test!")
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.