我无法弄清楚为什么在此模板中使用带有参数的{% 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]+)/$']