我有urls.py
定義的應用程序的URL如何通過URLNAME作爲一個變量URL標籤在Django
urlpatterns = [
url(r'^group/create', create_group, name='create_group'),
url(r'^account/create', create_account, name='create_account'),
]
上下文包含
{'buttons': {'create_account': {'btn_text': 'Create Account',
'secondary': 'Add a new accounting ledger',
'url': 'create_account'}}
我應該如何在模板中使用的URL。
{% for button in buttons %}
<li class="collection-item">
<div>
{% with btn_url=button.url %}
<a class="btn" href="{% url btn_url %}">{{ button.btn_text }}</a>
{% endwith %}
<span class="black-text">{{ button.secondary }}</span>
</div>
</li>
{% endfor %}
在模板上面的代碼拋出
Reverse for '' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
我應該如何通過URL名稱爲變量到url
模板標籤? 或者如果我應該如何在我的視圖本身生成整個網址,該網址應該如何生成?
謝謝。我沒有試過這個。我建議使用@ reverse。 – eskawl