为什么我的 urls.py 不起作用?
url(r'^video/?$','stuff.abc.views.video',name="video"),
这不起作用:
<a href="{% url video %}">Videos</a>
但这有效:
<a href="/video">Videos</a>
错误是:
TemplateSyntaxError at /
Caught ViewDoesNotExist while rendering: Tried ad in module stuff.abc.views. Error was: 'module' object has no attribute 'ad'
url(r'^video/?
This doesn't work:
<a href="{% url video %}">Videos</a>
But this works:
<a href="/video">Videos</a>
the error is:
TemplateSyntaxError at /
Caught ViewDoesNotExist while rendering: Tried ad in module stuff.abc.views. Error was: 'module' object has no attribute 'ad'
,'stuff.abc.views.video',name="video"),
This doesn't work:
But this works:
the error is:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
url 本身并没有破坏任何东西,而是
stuff.abc.views
模块出现了错误。在该模块中的某个位置(可能在
video
视图函数中),您尝试访问一个不存在的名为ad
的属性。该错误很令人困惑,因为它显示的是 ViewDoesNotExist,但这实际上只是 Django 感到困惑,因为它希望因不同的原因而捕获属性错误。
The url itself isn't breaking things, it's the
stuff.abc.views
module that has the error.Somewhere in that module (and probably in the
video
view function), you are attempting to access an attribute calledad
that doesn't exist.The error is confusing because it says
ViewDoesNotExist
, but that's really just Django getting confused because it expects to be catching anattribute error
for a different reason right there.