属性错误:“搜索”对象没有属性“status_code”在 Django 项目中
我正在使用测试服务器测试 django 项目,当它给我以下异常时
回溯(最近一次调用最后一次):
文件“/usr/lib/pymodules/python2.6/django/core/servers/basehttp.py”,第280行,运行中 self.result = application(self.environ, self.start_response)
文件“/usr/lib/pymodules/python2.6/django/core/servers/basehttp.py”,第674行,>调用 返回 self.application(environ, start_response)
文件“/usr/lib/pymodules/python2.6/django/core/handlers/wsgi.py”,第 245 行,调用 响应 = middleware_method(请求,响应)
文件“/usr/lib/pymodules/python2.6/django/middleware/common.py”,第 84 行,>process_response 如果response.status_code == 404:
属性错误:“搜索”对象没有属性“status_code”
仅通过阅读此回溯,我认为问题不在我的代码中,但我不确定。有人可以查看我的代码并帮助我解决这个问题吗?我的代码托管在 GitHub 上,非常感谢任何其他评论或建议。预先感谢您的时间和考虑。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
MusicGrep/musicgrep/views.py
未返回 HttpResponse 实例MusicGrep/musicgrep/views.py
is not returning a HttpResponse instance您的代码存在很多问题,但导致您引用的实际错误的问题是您没有在 urlconf 中实例化 FormWizard 子类。
作为 文档显示,您需要实际调用 urls.py 中的
search
类来实例化它,因此您传递的是实例而不是类。如果您遵循 PEP8 命名指南,这可能会有所帮助 - 如果您的类被称为
Search
并且带有大写的 S,那么更明显的是它实际上是一个类而不是一个函数。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.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.