2016-04-28 52 views
4

我想根據頁面列表構建一個動態的URL列表。帶有可變Django模板的動態URL

在我的urls.py,整個應用程序的命名空間base背後:

urlpatterns = patterns('', 
    url(r'^(?P<pk>[\w]+)/title/$', TitleSection.as_view(), name='title'), 
    url(r'^(?P<pk>[\w]+)/amount/$', AmountSection.as_view(), name='amount'), 
    url(r'^(?P<pk>[\w]+)/description/$', DescriptionSection.as_view(), name='description'),) 

在我context數據,我有以下列表:

sections: ['title', 'amount', 'description'] 

我試圖建立爲部分中的每個元素指定u​​rl。

我試過如下:

{% for section in sections %} 
    <a href="{% url "base:"+section pk=object.id %}">..</a> 
{% endfor %} 

但我得到了以下錯誤:

Could not parse the remainder: '+section' from '"base:"+section'

然後我嘗試:

<a href="{% url "base:{{section}}" pk=project.id %}">{{ section }}</a> 

錯誤:

Reverse for '{{section}}' with arguments '()' and keyword arguments '{u'pk': 77}' not found. 0 pattern(s) tried: []

你知道該怎麼做嗎?

+0

嘗試從去掉 「的」 href如:.. Dovi

回答