Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 基于django类的视图中的多分页-listview_Python_Django_Django Views_Django Class Based Views - Fatal编程技术网

Python 基于django类的视图中的多分页-listview

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_

下面的代码对查询集进行分页,但如何对上下文['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_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您可以给出一个如何使用基于类的视图的示例。