I'm building a simple blog app using Django.
This app has a main template blog.html
which is shared between the following views:
blog (url:
/blog/[page number]
)
Main page of the blog, displays the last articlessearch (url:
/search/<query>/[page number]
)
Will display the articles who match the querycategory (url:
/category/<category name>/[page number]
)
Will display the articles from the given category
Each a this views provides the template blog.html
with an object page
obtained using the function Paginator
each time with a different objects list (depending on the view).
Here is my problem:
The template blog.html
contains a pager
<ul class="pager">
{% if page.has_previous %}
<li class="previous">
<a href="{{ url_previous_page }}" class="btn btn-primary" >← Older</a>
</li>
{% endif %}
{% if page.has_next %}
<li class="next">
<a href="{{ url_next_page }}" class="btn btn-primary" >Newer →</a>
</li>
{% endif %}
</ul>
How can I define in an elegant way the values of url_next_page
and url_previous_page
in all the views?