Django分頁器帶樓層

2021-10-04 21:11:35 字數 1146 閱讀 7926

我這裡有個例子,需要的直接呼叫。我暫時還沒時間研究這個forloop。

def

index

(request)

: comment_obj = comment.objects.

all()

currentpage =

int(request.get.get(

'page',1

))paginator = paginator(comment_obj,10)

if(currentpage ==

none):

page=

1 strat =

(int

(currentpage)-1

)*10if paginator.num_pages >11:

if currentpage -

5<1:

pagerange =

range(1

,11)elif currentpage +

5> paginator.num_pages:

pagerange =

range

(paginator.num_pages -

9, paginator.num_pages +1)

else

: pagerange =

range

(currentpage -

5, currentpage +5)

else

: pagerange = paginator.page_range

try: comment_obj = paginator.page(currentpage)

except pagenotaninteger:

comment_obj = paginator.page(1)

except emptypage:

comment_obj = paginator.page(1)

return render(request,'index.html,local(

))

我這裡前後端沒有分離,因為公司的前端是個菜逼。

前端模板:

} 樓層:}}

Django元件 分頁器

批量匯入資料 booklist for i in range 100 book.objects.bulk create booklist 分頁器的使用 book list book.objects.all paginator paginator book list,10 print count pa...

Django元件 分頁器

批量匯入資料 booklist for i in range 100 book.objects.bulk create booklist 分頁器的使用 book list book.objects.all paginator paginator book list,10 print count pa...

django 裝飾器和分頁器

2.建立裝飾器 else url request.get full path ret redirect reverse users user login ret.set cookie url url return ret return login handler views.py 登入檢視函式中 實...