{% if items.paginator.count %} {# to suppress if only one page, check items.paginator.num_pages > 1 #}
Pages:
{# always link to the first page, even if it is not listed in pages to be shown #}
{% if 1 not in show_pages %}{% firstof first_page_label 1 %} {% endif %}
{% for page, label in show_pages.items %}
{% if forloop.first and page > 2 %} ... {% endif %} {# gap before page 1 #}
{% ifequal page items.number %} {% firstof label page %} {# current page #}
{% else %}{% firstof label page %}
{% endifequal %}
{% if forloop.last and page|add:1 < items.paginator.num_pages %} ... {% endif %} {# gap before last page #}
{% endfor %}
{# always link to the last page, even if it is not listed in pages to be shown #}
{% if items.paginator.num_pages not in show_pages %}
{% firstof last_page_label items.paginator.num_pages %}
{% endif %}