【发布时间】:2020-09-27 09:12:07
【问题描述】:
我正在尝试在我的笔记列表中添加分页,但我遇到了 2 个参数错误。我不知道修复它。大家能告诉我怎么解决吗?
notes/views.py
class NotesListView(LoginRequiredMixin,ListView):
login_url = '/accounts/login/'
model = Notes
context_object_name = 'notes_data'
paginate_by = 3
def get_queryset(self):
return Notes.objects.filter(create_date__lte=timezone.now()).order_by('-create_date')
notes/notes_list.html
{% if is_paginated %}
{% if page_obj.has_previous %}
<a class ='btn btn-warning'href='?page=1'>first</a>
<a class ='btn btn-warning'href="?page={{page_obj.previous_page_number}}">Previous</a>
{% endif %}
{% for num in page_obj.paginator.page_range %}
{% if num == page_obj.number %}
<a class ='btn btn-warning'href="?page={{num}}">{{num}}</a>
{% elif num > page_obj.number|add: '-1' and num < page_obj.number|add: '1' %}
<a class ='btn btn-success'href="?page={{num}}">{{num}}</a>
{% endif %}
{% endfor %}
{% if page_obj.has_next %}
<a class ='btn btn-warning'href="?page={{page_obj.next_page_number}}">Next</a>
<a class ='btn btn-warning'href="?page={{page_obj.paginator.num_pages}}">Last</a>
{% endif %}
{% endif %}
【问题讨论】:
标签: python django django-forms django-views django-templates