views.py
def pdf_files(request): files = Prikazi.objects.all() paginator = Paginator(files, 2) page = request.GET.get('page') try: queryset = paginator.page(page) except PageNotAnInteger: queryset = paginator.page(1) except EmptyPage: queryset = paginator.page(paginator.num_pages) #return files context = { 'object_list':queryset, 'files':files } return render(request, 'portal/pdf_files.html', context)
pdf_files.html
{% extends 'portal/index.html' %} {% block right %} <h1>PDF - файлы</h1> {% for file in files %} <table class="table_pdf"> <tr> <td><a href="{{ file.pdf_file.url }}" target="_blank">{{ file.title }}</a></td> </tr> </table> {% endfor %} <div class="paginator"> {% if object_list.has_privious %} <a href="?page={{ files.previous_page_number }}"><-</a> {% endif %} {% for num in queryset.paginator.page_range %} {% if num == object_list.number %} <span class="current"><b>{{ num }}</b></span> {% else %} <a href="?page={{ num }}"> {{ num }}</a> {% endif %} {% endfor %} {% if object_list.has_next %} <a href="?page={{ object_list.next_page_number }}">-></a> {% endif %} </div> {% endblock %}