django无类型对象没有属性状态

时间:2010-11-19 07:20:01

标签: python django

我从Django得到以下错误:

  

NoneType对象没有属性status_code

以下是日志输出的副本:

Environment:

Request Method: GET
Request URL: http://192.168.2.206:8080/institutes_admin/
Django Version: 1.1.1
Python Version: 2.6.5
Installed Applications:
['django.contrib.auth',
 'django.contrib.admin',
 'django.contrib.contenttypes',
 'django.contrib.markup',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.comments',
 'mysite.registration',
 'mysite.profiles',
 'mysite.epw',
 'mysite.remember_me',
 'mysite.avatar',
 'mysite.django_documents',
 'mysite.inlines',
 'mysite.blog',
 'mysite.forum',
 'tagging']
Installed Middleware:
('django.middleware.cache.UpdateCacheMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.cache.FetchFromCacheMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'mysite.remember_me.views.AutoLogout')


Traceback:
File "/usr/lib/pymodules/python2.6/django/core/handlers/base.py" in get_response
  92.                 response = callback(request, *callback_args, **callback_kwargs)
File "/usr/lib/pymodules/python2.6/django/utils/decorators.py" in _wrapped_view
  56.                 result = middleware.process_response(request, response)
File "/usr/lib/pymodules/python2.6/django/middleware/cache.py" in process_response
  80.         if not response.status_code == 200:

Exception Type: AttributeError at /institutes_admin/
Exception Value: 'NoneType' object has no attribute 'status_code'

4 个答案:

答案 0 :(得分:4)

institutes_admin URL提供服务的视图不会返回响应,因此中间件在尝试缓存时会死亡。您需要发布该视图的代码 - 请在此处进行,而不是在单独的粘贴网站上。

答案 1 :(得分:1)

某处您丢失了响应对象。

如果autologout有process_response方法,我会看那里。如果你添加autologout和视图的代码,找到问题可能会非常快。

答案 2 :(得分:0)

当我尝试查看路由my / history / page时,我遇到了类似的异常错误,它从logentry和所有历史对象中获取数据。

此外,我还从xls表解析到REST API框架。一旦我从xls表解析到REST API框架。所以当我查看管理页面时,我丢失了很少的对象(数据)。当我从postgresql中删除数据库时。重新创建了所有数据库,创建了超级用户的孩子们的东西。

再次将数据从解析文件转储到REST API。这一切都得到了解决。

在你的情况下,我可能完全错了,但是对我来说,它可以解决以下错误

    AttributeError at /history/

'NoneType' object has no attribute 'pk'

Request Method:     GET
Request URL:    http://127.0.0.1:8000/history/
Django Version:     1.7.2
Exception Type:     AttributeError
Exception Value:    

'NoneType' object has no attribute 'pk'

Exception Location:     /home/praneeth/wru-pam/pam_site/rev_history/views.py in history_list, line 12
Python Executable:  /home/praneeth/wru-pam/venv/bin/python
Python Version:     3.4.0
Python Path:    

['/home/praneeth/wru-pam/pam_site',
 '/home/praneeth/wru-pam/venv/src/django-reversion-compare',
 '/home/praneeth/wru-pam/venv/lib/python3.4',
 '/home/praneeth/wru-pam/venv/lib/python3.4/plat-x86_64-linux-gnu',
 '/home/praneeth/wru-pam/venv/lib/python3.4/lib-dynload',
 '/usr/lib/python3.4',
 '/usr/lib/python3.4/plat-x86_64-linux-gnu',
 '/home/praneeth/wru-pam/venv/lib/python3.4/site-packages']

Server time:    Wed, 18 Mar 2015 14:22:32 +0000

Environment:


Request Method: GET
Request URL: http://127.0.0.1:8000/history/

Django Version: 1.7.2
Python Version: 3.4.0
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'rest_framework',
 'corsheaders',
 'pam',
 'reversion',
 'djcelery',
 'rev_history',
 'reversion_compare')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 'corsheaders.middleware.CorsMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'reversion.middleware.RevisionMiddleware',
 'simple_history.middleware.HistoryRequestMiddleware')


Traceback:
File "/home/praneeth/wru-pam/venv/lib/python3.4/site-packages/django/core/handlers/base.py" in get_response
  111.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/praneeth/wru-pam/pam_site/rev_history/views.py" in history_list
  12.         version_list = Version.objects.filter(object_id=i.object.pk)

Exception Type: AttributeError at /history/
Exception Value: 'NoneType' object has no attribute 'pk'

答案 3 :(得分:-5)

您正在对尚不存在的对象调用status_code。将一些测试数据添加到数据库中。 Nonetype相当于java的Null ......对象为null。