from django import template

register = template.Library()

def paginator(context, adjacent_pages=4):
    """
    To be used in conjunction with the object_list generic view.

    Adds pagination context variables for use in displaying first, adjacent and
    last page links in addition to those created by the object_list generic
    view.
    """
    page_numbers = [n for n in range(context["page"] - adjacent_pages, context["page"] + adjacent_pages + 1) if n > 0 and n <= context["pages"]]
    return {
        "hits": context["hits"],
        "results_per_page": context["results_per_page"],
        "page": context["page"],
        "pages": context["pages"],
        "page_numbers": page_numbers,
        "next": context["next"],
        "previous": context["previous"],
        "has_next": context["has_next"],
        "has_previous": context["has_previous"],
        "show_first": 1 not in page_numbers,
        "show_last": context["pages"] not in page_numbers,
    }

register.inclusion_tag("navigation/paginator.html", takes_context=True)(paginator)

from django import template

register = template.Library()

def paginator(context, adjacent_pages=4):
    """
    To be used in conjunction with the object_list generic view.

    Adds pagination context variables for use in displaying first, adjacent and
    last page links in addition to those created by the object_list generic
    view.
    """
    paginator = context["paginator"]
    page_obj = context["page_obj"]
    page_numbers = [n for n in range(context["page"] - adjacent_pages, context["page"] + adjacent_pages + 1) if n > 0 and n <= paginator.num_pages]
    return {
        "hits": paginator.count,
        "page": context["page"],
        "pages": paginator.num_pages,
        "page_numbers": page_numbers,
        "next": page_obj.next_page_number,
        "previous": page_obj.previous_page_number,
        "has_next": page_obj.has_next,
        "has_previous": page_obj.has_previous,
        "show_first": 1 not in page_numbers,
        "show_last": paginator.num_pages not in page_numbers,
    }

register.inclusion_tag("navigation/paginator.html", takes_context=True)(paginator)

Update after forum views now is class based