cardNum = 4
messages = Message.objects.filter(tree=0).order_by("-date_comment")
from django.core.paginator import Paginator
# 每一页要几条动态
cardNum = 4
paginator = Paginator(messages, cardNum)
page_number = request.GET.get('page', 1)
# 当前页码
n = int(page_number)
# 总页码
totalNum = math.ceil(messages.count()/cardNum)
# 取最后一页的个数
if messages.count() % cardNum == 0:
reNum = cardNum
else:
reNum = messages.count() % cardNum
if n == totalNum:
addNum = 0
else:
addNum = (totalNum - n) * cardNum - (cardNum - reNum)
<span>MESSAGE #{{ forloop.revcounter|add:addNum }}</span>
<!-- 分页器-->
{% if message %}
<div class="pagination col-12 ta-anime-pagination mt-3">
{% if message.has_previous %}
<a href="?page=1">
<i class="las la-angle-double-left"></i>
</a> 
<a href="?page={{ message.previous_page_number }}">
<i class="las la-angle-left"></i>
</a> 
{% endif %}
{% for page in allPage %}
{% if page == n %}
<a href="?page={{ page }}">
<i class="las la-cookie-bite"></i>
</a> 
{% else %}
<a href="?page={{ page }}">{{ page }}</a> 
{% endif %}
{% endfor %}
{% if message.has_next %}
<a href="?page={{ message.next_page_number }}">
<i class="las la-angle-right"></i>
</a> 
<a href="?page={{ message.paginator.num_pages }}">
<i class="las la-angle-double-right"></i>
</a>
{% endif %}
</div>
{% endif %}
<span>MESSAGE #{{ forloop.revcounter|add:addNum }}</span>
import json
import uuid
import math
from json import dumps
from django.core.paginator import Paginator
from django.http import HttpResponse
from django.shortcuts import render, redirect
from townbase.models import *
from townbase.views.method import *
def message_view(request):
# 留言数据
messages = Message.objects.filter(tree=0).order_by("-date_comment")
# 留言回复数据
reply = Message.objects.exclude(tree=0).order_by("date_comment")
# 每一页要几条动态
cardNum = 4
paginator = Paginator(messages, cardNum)
page_number = request.GET.get('page', 1)
# 当前页码
n = int(page_number)
# 分页过的数据
message = paginator.get_page(n)
# 总的页数,是个range
allPage = page(n, paginator)
# 总页码
totalNum = math.ceil(messages.count()/cardNum)
# 取最后一页的个数
if messages.count() % cardNum == 0:
reNum = cardNum
else:
reNum = messages.count() % cardNum
if n == totalNum:
addNum = 0
else:
addNum = (totalNum - n) * cardNum - (cardNum - reNum)
return render(request, 'block/message.html', locals())
此页面不支持夜间模式!
已进入夜间模式!
已进入普通模式!
搜索框不允许为空
签到成功!经验+5!芋圆币+2!
签到失败!今日已签到!
需要登录社区账号才可以进入!