简体   繁体   English

如何在Django模板中使用名称空间而不是硬编码的URL进行分页

[英]how to use name space instead of hard coded url in django templales for pagination

i am newbie in django,i have django templates where i have added the following code for pagination.here you can see that i have apply hard coded url for pagination.but i don't want to use hard coded url ,i want to use namespace instead of the hard coded url .how can i do this. 我在Django的新手,我已经在那里我已经添加了下面的代码pagination.here你可以看到,我有适用的硬编码的URL pagination.but我不希望使用硬编码的网址 Django模板,我想使用名称空间而不是硬编码的网址 。我该怎么办。

Template: 模板:

<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>

my urls: 我的网址:

url(r'^(?P<chain_pk>[0-9]+)/full/combination/$',
    CombinationSearchList.as_view(), name='dash_combination_search_list'),

Update 更新资料

my django version is 1.6 我的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>

Please note that I have used point.id on the url to provide the value for the point.id in your hardcoded url. 请注意,我用point.id的URL提供您的硬编码网址的point.id值。 This can be any other variable, like object.pk or object.id or any other context variable. 这可以是任何其他变量,例如object.pkobject.id或任何其他上下文变量。 If this is not clear post again with the view code of the page and I can help. 如果还不清楚,请再次发布页面的查看代码,我可以为您提供帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM