Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AttributeError: 'search' object has no attribute 'status_code' in django project

I'm testing a django project using the test sever when it gives me the following exception

Traceback (most recent call last):

File "/usr/lib/pymodules/python2.6/django/core/servers/basehttp.py", line 280, in run self.result = application(self.environ, self.start_response)

File "/usr/lib/pymodules/python2.6/django/core/servers/basehttp.py", line 674, in >call return self.application(environ, start_response)

File "/usr/lib/pymodules/python2.6/django/core/handlers/wsgi.py", line 245, in call response = middleware_method(request, response)

File "/usr/lib/pymodules/python2.6/django/middleware/common.py", line 84, in >process_response if response.status_code == 404:

AttributeError: 'search' object has no attribute 'status_code'

Just from reading this traceback, I don't think the problem is in my code, but I'm not sure. Could someone look through my code and help me solve this problem? my code is hosted on GitHub and any other comments or suggestions are greatly appreciated. Thanks in advance for your time and consideration.

like image 329
Levi Campbell Avatar asked Apr 03 '11 21:04

Levi Campbell


2 Answers

MusicGrep/musicgrep/views.py is not returning a HttpResponse instance

like image 185
Jerzyk Avatar answered Oct 23 '22 04:10

Jerzyk


There are quite a few problems with your code, but the one that's causing the actual error you quote is that you don't instantiate your FormWizard subclass in your urlconf.

As the documentation shows, you need to actually call the search class in urls.py to instantiate it, so you pass an instance rather than a class.

(r'^MusicGrep/$', 'MusicGrep.musicgrep.forms.search()'),

It might help if you followed the PEP8 guidelines on naming - if your class was called Search with a capital S, it would be more obvious that it was actually a class and not a function.

like image 22
Daniel Roseman Avatar answered Oct 23 '22 04:10

Daniel Roseman