請問在Django中使用ListView分頁時,如何確定物件/頁面顯示的數量(不是頁面數量)。
這是我在Views.py中的代碼 :
from django.shortcuts import render
from django.views。 generic import ListView, DetailView。
from .models importPost
class PostList(ListView)。
model=Post(span="hljs-title class_">ListView)
context_object_name='all_post'。
ordering=['-created_at']
謝謝你!
uj5u.com熱心網友回復:
只要在你的視圖中添加paginate_by = <頁面中的專案數>即可。
例如:
from django.shortcuts import render
from django.views.gener import ListView, DetailView
from .models import Post
class PostList(ListView)。
model=Post
context_object_name='all_post'。
ordering=['-created_at']
paginate_by = 10 # 10 items in a page[/span
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/332352.html
標籤:
