Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Django(mod_wsgi)-HttpBasicAuthentication使用视图装饰器-AttributeError_Django_Apache_Http_Authentication_Decorator - Fatal编程技术网

Django(mod_wsgi)-HttpBasicAuthentication使用视图装饰器-AttributeError

Django(mod_wsgi)-HttpBasicAuthentication使用视图装饰器-AttributeError,django,apache,http,authentication,decorator,Django,Apache,Http,Authentication,Decorator,我正在写一个小应用程序。我希望使用我找到的视图装饰器。 这是,这是。 我有一个Apache服务器(2.2)正在运行,Django是最新的。 我装饰了一个视图,当尝试获取它时,会出现AttributeError: Request Method: GET Request URL: http://localhost/redb/test/ Django Version: 1.5.1 Python Version: 2.7.5 Installed Applications: ('django.contr

我正在写一个小应用程序。我希望使用我找到的视图装饰器。 这是,这是。 我有一个Apache服务器(2.2)正在运行,Django是最新的。 我装饰了一个视图,当尝试获取它时,会出现AttributeError:

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'
我就是这样使用它的:

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

谢谢

decorator接受一个参数,因此您必须调用decorator,即使您没有提供参数
realm
,并让它默认为“”