I always end up rewriting this code .. well it was the last time:
pagination.inc.html
{% spaceless %}
{% if is_paginated %}
<ul class="pagination">
{% if has_previous %}
<li><a href="../{{ previous }}">« Prev</a></li>
{% endif %}
{% if show_first %}
<li><a href="../1">1</a></li><li><span>...</span></li>
{% endif %}
{% for linkpage in page_range %}
{% ifequal linkpage page %}
<li class="active"><span>{{ page }}</span></li>
{% else %}
<li><a href="../{{ linkpage }}">{{ linkpage }}</a></li>
{% endifequal %}
{% endfor %}
{% if show_last %}
<li><span>...</span></li><li><a href="?page=last">{{ pages }}</a></li>
{% endif %}
{% if has_next %}
<li><a href="../{{ next }}">Next »</a></li>
{% endif %}
</ul>
{% endif %}
{% endspaceless %}
Update: just added the css:
pagination.css
.pagination {
height:26px;
background:#c30;
clear:both;
margin:0;padding:0;
}
.pagination li {
float:left;
list-style:none;
margin:0;padding:0;
}
.pagination li span,
.pagination li a {
display:block;
padding:4px;
}
I'd make a templatetag, it's shorter to copy/paste once you installed it :)
Alternatively ... http://github.com/ericflo/django-pagination
Nice code, but it is next to impossible to read the dark blue on the black background.
@mat
I usually don't copy paste it ..
{% include "pagination.inc.html" %}Not much longer than a template tag and it allow me to keep my HTML code where it belongs .. in a template.
@Dan
Fixed.
Great post! Thanks for sharing!
term papers
Very informative site. I learn new code because of your post. Thanks for sharing. Excellent sites.
I visited your blog for the first time and just been your fan. Keep posting as I am gonna come to read it everyday.Your post is very informative. I learn new code because of your post. Thanks for sharing.