[英]Django: URL template tag leads to 404, but correct when hard coded
[英]how to use name space instead of hard coded url in django templales for pagination
我在Django的新手,我已經在那里我已經添加了下面的代碼pagination.here你可以看到,我有適用的硬編碼的URL pagination.but我不希望使用硬編碼的網址 Django模板,我想使用名稱空間而不是硬編碼的網址 。我該怎么辦。
模板:
<span class="page-links">
{% if page_obj.has_previous %}
{% if query_string %}
<a href="/dash/{{ point.id }}/full/combination/?page={{ page_obj.previous_page_number }}&{{ query_string }}">previous</a>
{% else %}
<a href="/dash/{{ point.id }}/full/combination/?page={{ page_obj.previous_page_number }}">previous</a>
{% endif %}
{% endif %}
</span>
我的網址:
url(r'^(?P<chain_pk>[0-9]+)/full/combination/$',
CombinationSearchList.as_view(), name='dash_combination_search_list'),
更新資料
我的Django版本是1.6
<span class="page-links">
{% if page_obj.has_previous %}
{% if query_string %}
<a href="{% url 'dash_combination_search_list' point.id %}?page={{ page_obj.previous_page_number }}&{{ query_string }}">previous</a>
{% else %}
<a href="{% url 'dash_combination_search_list' point.id %}?page={{ page_obj.previous_page_number }}">previous</a>
{% endif %}
{% endif %}
</span>
請注意,我用point.id
的URL提供您的硬編碼網址的point.id值。 這可以是任何其他變量,例如object.pk
或object.id
或任何其他上下文變量。 如果還不清楚,請再次發布頁面的查看代碼,我可以為您提供幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.