简单的Django反向URL,参数不起作用

时间:2016-12-06 15:10:31

标签: python django django-urls

我无法弄清楚为什么在此模板中使用带有参数的{% url %}的这种情况会让我感到沮丧。我以前做过它并且工作正常但是我找不到这段代码的错误。

urls.py

url(r'^promotions/$', views.promotions, name="promotions"),
url(r'^promotions/(?P<title>[-\w]+)/$', views.promotion_detail, name="promotions_detail"),

promotion.html

    {% for promotion in promotions %}
    <div class="a-promotion">
        <div class="column-1">
            <div class="title">{{promotion.title}}</div>
            <div class="offer">{{promotion.amount}}</div>
        </div>
        <div class="column-2">
            **********THE LINE BELOW THROWS THE ERROR******************
            {{promotion.short_description}}... <a href="{% url 'promotions_detail' title=promotion.title %}"><span class="learn-more">Learn More</span></a>
        </div>
    </div>
    {% endfor %}

错误: NoReverseMatch at / promotions /

Reverse for 'promotions_detail' with arguments '()' and keyword arguments '{u'title': u'Welcome to Our Site'}' not found. 1 pattern(s) tried: ['promotions/(?P<title>[-\\w]+)/$']

0 个答案:

没有答案
相关问题