【问题标题】:Why doesn't my urls.py work?为什么我的 urls.py 不起作用?
【发布时间】:2011-07-11 13:07:48
【问题描述】:
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'

【问题讨论】:

  • 文件的其余部分说...?
  • 哪个文件?模板,还是 urls.py?这是模板中唯一的东西。
  • 是的,我得说这个错误看起来与你的 sn-p 无关。 sn-p 中没有提到“ad”,但您的错误消息抱怨“ad”不存在。看起来你正试图在查询字符串上传递一些东西——查看 Django 的文档以了解如何处理这个问题。

标签: python html django templates


【解决方案1】:

url 本身并没有破坏,它是 stuff.abc.views 模块有错误。

在该模块的某处(可能在video 视图函数中),您正试图访问一个名为ad 的不存在的属性。

该错误令人困惑,因为它显示的是 ViewDoesNotExist,但这实际上只是 Django 感到困惑,因为它希望在那里捕获 attribute error 的原因不同。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-06-17
    • 2018-05-05
    • 2015-09-25
    • 2018-03-05
    • 2013-04-19
    • 2015-10-17
    • 2016-02-20
    • 2023-04-03
    相关资源
    最近更新 更多