Python 基于django类的视图中的多分页-listview
下面的代码对查询集进行分页,但如何对上下文['guser1'进行分页Python 基于django类的视图中的多分页-listview,python,django,django-views,django-class-based-views,Python,Django,Django Views,Django Class Based Views,下面的代码对查询集进行分页,但如何对上下文['guser1'进行分页 class AuthorList(ListView): template_name = 'authorList.html' paginate_by = 10 queryset = Author.objects.order_by('date') def get_context_data(self, **kwargs): context = super(AuthorList, self).get_
class AuthorList(ListView):
template_name = 'authorList.html'
paginate_by = 10
queryset = Author.objects.order_by('date')
def get_context_data(self, **kwargs):
context = super(AuthorList, self).get_context_data(**kwargs)
context['guser1'] = Author.objects.order_by('date')
return context
您必须像在视图中一样使用
Paginator
对象。以下是。可以在模板中的上下文变量page\u obj
下访问视图的分页器。页码作为GET参数在url中传递,page
。下面是一个简单的例子:
{% if page_obj.has_previous %}
<a href="{% url "your_view_url" %}?page={{ page_obj.previous_page_number }}">Previous page</a>
{% endif %}
{% if page_obj.has_next %}
<a href="{% url "your_view_url" %}?page={{ page_obj.next_page_number }}">Next page</a>
{% endif %}
{%if page_obj.has_previous%}
{%endif%}
{%如果页面_obj.has_next%}
{%endif%}
Duplicate of您可以给出一个如何使用基于类的视图的示例。