day95-django-にはページングが付属しています

1 .views.py 

改ページ:Djangoのページ:前の、すべてのページのリストを、次のページでは、このアプローチは、より多くのデータ、には適していません私たちがページをカスタマイズする必要があります。
def index2(request):
     for i in range(300):
         name = 'root' + str(i)
         models.UserInfo2.objects.create(name = name、age = 18、ut_id = 1)#all

  linesリスト user_list = models.UserInfo2.objects.all() PER_PAGE 10あたりの ページネータ=ページネータ(user_list、10 現在のページ CURRENT_PAGE = request.GET.get(' ページ' 現在のページは、オブジェクトの 投稿= ページネータを.page(current_page) return render(request、' index2.html '、{ ' 投稿':投稿})
2 app01 

からの .urls.py インポートビュー
urlpatterns = [ 

    url(' index2.html ' 、views.index2)、

]
3.index2.html 

<body>
<ul>
  <!-ページ
ごとに10行を表示-> {posts.object_list%}の行の%%
<li> {{row.name}} </ li>
{%endfor %}

<!-前のページがある場合、前のページ
番号を取得-> {%if posts.has_previous%}
<a href="/index2.html?page={{ posts.previous_page_number }}">前1つのページ</a>
{%endif%}

<!-次のページがある場合、次のページ
番号を取得します-> {%if posts.has_next%}
<a href = "/ index2.html?Page = { {posts.next_page_number}} ">次のページ</a>
{%endif%}
</ ul>

</ body>

 

おすすめ

転載: www.cnblogs.com/python-daxiong/p/12738414.html