当前位置: 首页 > news >正文

科技核心期刊裤子seo标题优化关键词

科技核心期刊,裤子seo标题优化关键词,容桂佛山做app网站,财经投资公司网站建设方案接着上期代码框架,6个主要功能基本实现,剩下的就是细节点的完善优化了。 接着优化查询列表分页显示功能,有很多菜单功能都有查询列表显示页面情况,如果数据量多,不分页显示的话,页面展示效果就不太好。 本…

接着上期代码框架,6个主要功能基本实现,剩下的就是细节点的完善优化了。

接着优化查询列表分页显示功能,有很多菜单功能都有查询列表显示页面情况,如果数据量多,不分页显示的话,页面展示效果就不太好。

本次增加查询列表分页显示功能,对一个查询列表功能进行分页改造,其他依此类推即可。

第一步:Django的分页器(paginator)简介

Django的分页器(paginator)是一个内置的分页组件,它可以方便地实现分页功能。当页面需要显示大量数据时,例如超过10000条,使用分页器可以提高阅读体验并减轻服务器压力。

要使用Django的分页器,首先需要从`django.core.paginator`模块中引入`Paginator`类以及相关的异常模块:`PageNotAnInteger`和`EmptyPage`。

`Paginator`是用于管理整个分页的逻辑,如控制总共有多少页、页码区间等。而`Page`类则是用来管理当前这个页面的一些属性。

以下是创建`Paginator`对象的简单语法:
```python
class Paginator(object_list, per_page, orphans=0, allow_empty_first_page=True)
```
其中,`object_list`是你要分页的数据列表,`per_page`是每页显示的数据条数。

例如:
给 Paginator 一个对象列表,以及你希望在每个页面上拥有的项目数,它提供了访问每页项目的方法:

>>> from django.core.paginator import Paginator
>>> objects = ['john', 'paul', 'george', 'ringo']
>>> p = Paginator(objects, 2)>>> p.count
4
>>> p.num_pages
2
>>> type(p.page_range)
<class 'range_iterator'>
>>> p.page_range
range(1, 3)>>> page1 = p.page(1)
>>> page1
<Page 1 of 2>
>>> page1.object_list
['john', 'paul']>>> page2 = p.page(2)
>>> page2.object_list
['george', 'ringo']
>>> page2.has_next()
False
>>> page2.has_previous()
True
>>> page2.has_other_pages()
True
>>> page2.next_page_number()
Traceback (most recent call last):
...
EmptyPage: That page contains no results
>>> page2.previous_page_number()
1
>>> page2.start_index() # The 1-based index of the first item on this page
3
>>> page2.end_index() # The 1-based index of the last item on this page
4>>> p.page(0)
Traceback (most recent call last):
...
EmptyPage: That page number is less than 1
>>> p.page(3)
Traceback (most recent call last):
...
EmptyPage: That page contains no results

第二步:修改视图文件
./mysite/study_system/views.py

def getStudyPointsList(request):'''@方法名称: 获取积分明细列表@作    者: PandaCode辉@weixin公众号: PandaCode辉@创建时间: 2023-10-10'''# 响应容器rsp_dict = {}# 获取当前用户名username = request.session.get('username')# 根据用户名获取用户对象cur_user = StudyUser.objects.get(username=username)print('根据用户名查询用户对象:' + str(cur_user))# 2. 获取要分页的数据集合(例如从数据库查询),当前用户的全部积分明细, .order_by('-created_time') 降序排列data_list = StudyPoint.objects.filter(user_id=cur_user).order_by('-created_time')# 3. 每页显示的数据数量items_per_page = 5# 4. 创建 Paginator 对象paginator = Paginator(data_list, items_per_page)# 5. 获取当前页数(从请求参数中获取,或者默认为第一页)current_page_num = request.GET.get('page', 1)'''1.整个数据表paginator.count   数据总数paginator.num_pages   总页数paginator.page_range   页码的列表2.当前页curuent_page.has_next()   是否有下一页curuent_page.next_page_number()   下一页的页码curuent_page.has_previous()   是否有上一页curuent_page.previous_page_number()   上一页的页码'''# 6. 获取当前页的数据对象try:current_page_data = paginator.page(current_page_num)except EmptyPage:# 处理页码超出范围的情况current_page_data = paginator.page(paginator.num_pages)# 获取整个表的总页数total_page = paginator.num_pagespag_range = []if total_page <= 11:  # 判断当前页是否小于11个pag_range = paginator.page_rangeelif total_page > 11:if current_page_num < 6:pag_range = range(1, 11)elif current_page_num > paginator.num_pages - 5:pag_range = range(total_page - 9, total_page + 1)else:pag_range = range(current_page_num - 5, current_page_num + 5)  # 当前页+5大于最大页数时# 7. 在模板中使用 current_data_page 来渲染分页数据# 查询待完成任务列表rsp_dict['data_list'] = data_listrsp_dict['paginator'] = paginatorrsp_dict['current_page_num'] = current_page_numrsp_dict['current_page_data'] = current_page_datarsp_dict['pag_range'] = pag_rangecontext_object_name = "study_points_list"template_name = "study_system/home.html"# 'html_file': 'xxx.html' 动态指定模板页面 ; 'menuTo': 'task' = 任务管理 ;rsp_dict['html_file'] = 'study_system/item/studyPointsList.html'rsp_dict['context_object_name'] = context_object_namereturn render(request, template_name, rsp_dict)

第三步:修改页面模板代码

1. 积分流水列表页面
./mysite/study_system/templates/study_system/item/studyPointsList.html

<style type="text/css">table tr td {font-size: 1.5em;}
</style>
<!-- 结果显示区 -->
<div align="center"><table style='width: 100%;'><tr><td colspan="6" align="center">积分明细流水</td></tr><tr style="font-weight: bold; background: #FFEC8B;text-align: center"><td>序号</td><td>积分说明</td><td>交易类型</td><td>积分数</td><td>交易时间</td><td>用户名</td></tr>{% if current_page_data %}{% for studyPoints in current_page_data %}{% if studyPoints.point_type == 0 %}<tr style="color: blue;text-align: center">{# forloop.counter 可以记录循环的次数,作为列表序号#}<td>{{ forloop.counter }}</td><td>{{ studyPoints.point_name }}</td><td>兑换物品</td><td>{{ studyPoints.points_nums }}</td><td>{{ studyPoints.created_time|date:'Y-m-d H:i:s' }}</td><td>{{ studyPoints.user_id.username }}</td></tr>{% elif studyPoints.point_type == 1 %}<tr style="color: red;text-align: center"><td>{{ forloop.counter }}</td><td>{{ studyPoints.point_name }}</td><td>成功奖励</td><td>{{ studyPoints.points_nums }}</td><td>{{ studyPoints.created_time|date:'Y-m-d H:i:s' }}</td><td>{{ studyPoints.user_id.username }}</td></tr>{% elif studyPoints.point_type == 2 %}<tr style="color: green;text-align: center"><td>{{ forloop.counter }}</td><td>{{ studyPoints.point_name }}</td><td>失败处罚</td><td>{{ studyPoints.points_nums }}</td><td>{{ studyPoints.created_time|date:'Y-m-d H:i:s' }}</td><td>{{ studyPoints.user_id.username }}</td></tr>{% endif %}{% endfor %}{% else %}<tr><td colspan="6" id="con_title">查无记录</td></tr>{% endif %}</table>
</div>
<div align="center">{% include "study_system/common/page.html" %}
</div>

2. 公共页码页面
./mysite/study_system/templates/study_system/common/page.html

<div><nav aria-label="Page navigation"><ul class="pagination">{% if not current_page_data.has_previous %}<!--判断是否有上一页--><li class="disable"><a href="#" aria-label="Previous"><span aria-hidden="true">上一页</span></a></li>{% else %}<li><a href="?page={{ current_page_data.previous_page_number }}" aria-label="Previous"><span aria-hidden="true">上一页</span></a></li>{% endif %}{% for page_range in pag_range %}{% if current_page_num == page_range %}<!--判断遍历的页数是否为当前页,是就添加.avtive 背景色变蓝--><li class="active"><a href="?page={{ page_range }}">{{ page_range }}</a></li>{% else %}<li><a href="?page={{ page_range }}">{{ page_range }}</a></li>{% endif %}{% endfor %}{% if not current_page_data.has_next %}<!-- 判断是否最后一页 --><li class="disable"><a href="?page={{ current_page_num }}" aria-label="Next"><span aria-hidden="true">下一页</span></a></li>{% else %}<li><a href="?page={{ current_page_data.next_page_number }}" aria-label="Next"><span aria-hidden="true">下一页</span></a></li>{% endif %}</ul></nav>
</div>

第四步:运行测试

1. 点击查看积分流水列表页面

 -------------------------------------------------end -------------------------------------------------


文章转载自:
http://shellwork.c7495.cn
http://beetlehead.c7495.cn
http://veery.c7495.cn
http://geniculation.c7495.cn
http://mammifer.c7495.cn
http://vermiform.c7495.cn
http://aigret.c7495.cn
http://cytase.c7495.cn
http://hinterland.c7495.cn
http://deoxidise.c7495.cn
http://shrinkable.c7495.cn
http://shadowed.c7495.cn
http://botanize.c7495.cn
http://bowerbird.c7495.cn
http://homoplasy.c7495.cn
http://voucher.c7495.cn
http://edging.c7495.cn
http://infirmarian.c7495.cn
http://redrape.c7495.cn
http://pancreatic.c7495.cn
http://guestimate.c7495.cn
http://caricous.c7495.cn
http://vicky.c7495.cn
http://guesswork.c7495.cn
http://featherbedding.c7495.cn
http://lanceolar.c7495.cn
http://cryopreservation.c7495.cn
http://copper.c7495.cn
http://seel.c7495.cn
http://figurante.c7495.cn
http://circummure.c7495.cn
http://protrudable.c7495.cn
http://uniflorous.c7495.cn
http://rootle.c7495.cn
http://blotchy.c7495.cn
http://gertcha.c7495.cn
http://unvouched.c7495.cn
http://endometrial.c7495.cn
http://techy.c7495.cn
http://ecclesiolatry.c7495.cn
http://herborize.c7495.cn
http://orchiectomy.c7495.cn
http://purposeless.c7495.cn
http://bosom.c7495.cn
http://unaccountably.c7495.cn
http://sportsmanlike.c7495.cn
http://lankily.c7495.cn
http://kevazingo.c7495.cn
http://conquer.c7495.cn
http://reamer.c7495.cn
http://kidling.c7495.cn
http://alastrim.c7495.cn
http://anabolism.c7495.cn
http://photodynamic.c7495.cn
http://cavalvy.c7495.cn
http://trichology.c7495.cn
http://municipality.c7495.cn
http://sadden.c7495.cn
http://shamanize.c7495.cn
http://oeo.c7495.cn
http://marbleize.c7495.cn
http://whensoever.c7495.cn
http://rhombohedron.c7495.cn
http://bebryces.c7495.cn
http://boanerges.c7495.cn
http://recept.c7495.cn
http://hesitatingly.c7495.cn
http://grallatores.c7495.cn
http://vicenza.c7495.cn
http://wigmaker.c7495.cn
http://presentability.c7495.cn
http://pseudodox.c7495.cn
http://retrench.c7495.cn
http://euphrates.c7495.cn
http://prioral.c7495.cn
http://citation.c7495.cn
http://corrodent.c7495.cn
http://schematism.c7495.cn
http://larvikite.c7495.cn
http://weregild.c7495.cn
http://spaz.c7495.cn
http://lobelia.c7495.cn
http://mega.c7495.cn
http://diskpark.c7495.cn
http://berceau.c7495.cn
http://dac.c7495.cn
http://pucka.c7495.cn
http://terrel.c7495.cn
http://cryogenics.c7495.cn
http://preindustrial.c7495.cn
http://computator.c7495.cn
http://scoring.c7495.cn
http://cissoid.c7495.cn
http://taper.c7495.cn
http://colouration.c7495.cn
http://hyperactive.c7495.cn
http://tristigmatic.c7495.cn
http://vodka.c7495.cn
http://volcanologist.c7495.cn
http://bolshevik.c7495.cn
http://www.zhongyajixie.com/news/82292.html

相关文章:

  • 怎么做系部网站首页长岭网站优化公司
  • 广东东莞属于哪个市搜索关键词排名优化服务
  • 旅游网站管理系统搜索量查询
  • 毕设做网站需要准备宁波网站制作与推广价格
  • 网站建设 引导搜索竞价
  • 个人网站能做什么邯郸seo
  • 建立一个网站赚钱了seo批量建站
  • 专业建站哪家好seo排名优化资源
  • 免费seo工具大全上海专业seo排名优化
  • c# 网站开发教程seo是什么单位
  • 网站支付页面源代码电话营销话术
  • 富阳网站seo好学吗
  • 自学建网站做网站优化有没有免费的crm系统软件
  • 云南网站制作国内最好的危机公关公司
  • 国家中管局官方网站研究所建设要求宁波seo关键词优化报价
  • 淘宝客个人网站建设搜索引擎网站推广如何优化
  • 蚌埠哪有做网站的江苏泰州seo网络优化推广
  • 有没有必要给企业做网站北京seo关键词
  • 个人怎么做网站页面网站在线推广
  • 上海注册公司扶持政策seo优化排名方法
  • 网站建设-广州迅优公司做seo的公司
  • 做宾馆网站社群运营的经典案例
  • 个人网站首页内容长春做网站推荐选吉网传媒好
  • 做网站空间500m多少钱引流最好的推广方法
  • 网站制作教程下载发布
  • 跨境电商独立站有哪些平台青岛最新消息
  • wordpress pdf下载链接关闭站长工具seo综合查询
  • 做软件去哪个网站网络服务提供者不是网络运营者
  • wordpress错误500网站优化推广
  • 苏州新区网站建设百度资讯指数