简体   繁体   中英

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.

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

<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. This can be any other variable, like object.pk or object.id or any other context variable. If this is not clear post again with the view code of the page and I can help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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