属性错误:“搜索”对象没有属性“status_code”在 Django 项目中

发布于 2024-10-30 06:26:25 字数 891 浏览 3 评论 0原文

我正在使用测试服务器测试 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

生生不灭 2024-11-06 06:26:25

MusicGrep/musicgrep/views.py 未返回 HttpResponse 实例

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

二货你真萌 2024-11-06 06:26:25

您的代码存在很多问题,但导致您引用的实际错误的问题是您没有在 urlconf 中实例化 FormWizard 子类。

作为 文档显示,您需要实际调用 urls.py 中的 search 类来实例化它,因此您传递的是实例而不是类。

(r'^MusicGrep/

如果您遵循 PEP8 命名指南,这可能会有所帮助 - 如果您的类被称为 Search 并且带有大写的 S,那么更明显的是它实际上是一个类而不是一个函数。

, 'MusicGrep.musicgrep.forms.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.

(r'^MusicGrep/

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.

, '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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文