I use django-pagination to paginate pages. It works great, but I would like to configure
<link rel="prev" href="http://www.example.com/foo/?page=1" /> <link rel="next" href="http://www.example.com/foo/?page=3" />
in <head> , for example, recommended by Google .
However, I did not find a way to do this (without additional requests, at least). At first I tried to edit pagination/templates/pagination.html with something like this
{% block extra_head %} <link rel=... ... /> {% endblock %}
Which, of course, did not work (pagination.html is included with the {% paginate %} tag, it does not extend my layout.html ). Then I tried to change my template for / foo / view to something like this (adding {% block extra_head %} ):
{# foo.html #} {% extends "layout.html" %} {% block content %} {% load pagination_tags %} {% autopaginate object_list %} {% paginate %} {% for obj in object_list %} {{ obj }} {% endfor %} {% paginate %} {% endblock %} {% block extra_head %} <link rel="prev" href="?page={{ page_obj.previous_page_number }}"/> {% endblock %}
But this will not work either, since the page_obj variable is only available in the {% block content %} . A may cause
{% autopaginate object_list %}
in the extra_head block, but that would mean an extra hit in db (and possibly other side effects that I don't know about). Is there an elegant way to solve this problem, ideally, as dry as possible?
Edit: I am using django 1.2.