2011-12-15 56 views
1

一起使用django的命名路由有問題。當叫如下Django的不斷提高NoReverseMatch錯誤:Django命名的路線不能與django.views.generic.simple.redirect_to

urlpatterns += patterns('django.views.generic.simple', 
# tutorials 
    url(r'^tutorials/?$', 'redirect_to', {'url':'/tutorials/markers/'}, name='tutorials'), 
    (r'^tutorials/markers/?$', 'direct_to_template', {'template': 'page_tutorials_markers.html'}), 
) 

# in template: 
<a href="{% url tutorials %}">tutorials</a> 

它看起來不言自明,但我想不通,爲什麼這條線路不被認爲具有具名的路線。

感謝,

Ĵ

回答

1

反向匹配往往當你有可選的字符失敗。 Django如何知道是否添加尾部斜槓?

我建議您刪除問號,強制URL以斜槓結尾,並依賴CommonMiddleware類來根據需要添加斜線。

+0

感謝您的帖子。這可能是很好的一般性建議,但這並不會改變這個問題。我已經拿出了兩個條目上的問號,問題依然存在。 – 2011-12-15 23:54:13