开发者

django none type object has no attribute status

开发者 https://www.devze.com 2023-01-25 17:35 出处:网络
I get the following error from Django: NoneType object has no attribute status_code Here\'s a copy of the output from the log:

I get the following error from Django:

NoneType object has no attribute status_code

Here's a copy of the output from the log:

Environment:

Request Method: GET
Request URL: http://192.168.2.206:808开发者_运维知识库0/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'


The view that serves the institutes_admin URL is not returning a response, so the middleware is dying when it tries to cache it. You need to post the code of that view - and please do it here, not on a separate paste site.


Somewhere you've lost your response object.

If autologout has a process_response method, I'd look there. If you add the code of autologout and the view, it'll probably be very fast to find the problem.


I had the similar exception error when I tried to look route my /history/ page which gets it data from logentry and all history objects stuff.

In addition I do parsing from xls sheet to REST API framework. Once I was doing parsing from xls sheet to REST API framework. so I lost few objects(data) when I looked into admin page. When I dropped the database from postgresql. recreated everything database, created super user kids stuff.

dumped data from parsing file to REST API again. This time everything got settled.

I might be completely wrong in your case but it worked for me to over come the below error

    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'


you are calling status_code on an object that doent exist yet. add some test data to the database. Nonetype is the equivalent of java's Null ... the object is null.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号