【问题标题】:"Reverse for '' with arguments '()' and keyword arguments '{}' not found. "“未找到带有参数 '()' 和关键字参数 '{}' 的 '' 的反向操作。”
【发布时间】:2012-07-08 04:07:11
【问题描述】:

我在 stackoverflow link 中应用了修复:

<a href="{% url shop_index %}"><span>{% trans "Shop List" %}</span></a>

urls.py:

url(r'^shop/$', 'index',  name="shop_index"),

但仍然是同样的错误。我哪里错了?

更新:


Django 1.5

Python 2.7.2

{% url shop_index %} 给出错误。如果我使用{% url 'shop_index' %},就可以了。


Django 1.5.dev17865

Python 2.7.3

{% url 'shop_index' %} 给出错误。如果我使用{% url shop_index %},就可以了。


这很奇怪。

【问题讨论】:

  • 你使用哪个 Django 版本?
  • 现在我正在我的云服务器中尝试。我部署了我的项目。 Django 版本是相同的。但是python版本不同。在服务器中,它给出了同样的错误。

标签: django django-templates django-urls


【解决方案1】:

尝试将shop_index 放在引号中:

<a href="{% url 'shop_index' %}">

如果没有引号,shop_index 将被视为模板变量而不是字符串。

【讨论】:

    猜你喜欢
    • 2023-04-03
    • 2015-02-18
    • 2010-12-22
    • 2013-12-07
    • 2015-08-29
    • 2014-05-29
    • 2013-07-25
    • 1970-01-01
    相关资源
    最近更新 更多