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

查看网站开发平台想做网站找什么公司

查看网站开发平台,想做网站找什么公司,上海专业seo,天津做网站比较好的公司目录 一、手动分页二、分页器分页 一、手动分页 1、概念 页码:很容易理解,就是一本书的页码每页数量:就是一本书中某一页中的内容(数据量,比如第二页有15行内容),这 15 就是该页的数据量 每一…

django-ide


目录

    • 一、手动分页
    • 二、分页器分页


一、手动分页

1、概念

  • 页码:很容易理解,就是一本书的页码
  • 每页数量:就是一本书中某一页中的内容(数据量,比如第二页有15行内容),这 15 就是该页的数据量

每一页的数据量我们可以自定义,比如每页我们要求只显示 10 条数据。

2、功能

比如有数据:1, 2, 3, …, 100

假设我们规定:

页码(page)= 1

每一页(per_page)= 10

页码(page)数据范围(per_page)下标范围切片范围
11 ~ 100 ~ 9[ 0 : 10 ]
211 ~ 2010 ~ 19[ 10 : 20 ]
321 ~ 3020 ~ 39[ 20 : 30 ]
n[ (page-1) * per_page : page * per_page ]

3、案例

实现功能:根据数据量与我们规定的每页数据量自动创建页码按钮,当点击页面对应的页码按钮时,跳转到对应的页码数据。

先创建一百多个测试数据:

image-20230820171104141

  • 视图

    import math
    from App.models import *
    from django.shortcuts import render, HttpResponsedef paginate(request, page=1):# 页码:page# 每页数量:per_pageper_page = 10# 获取数据库PersonModel的所有表数据persons = PersonModel.objects.all()# 对获取的表数据切片操作persons = persons[(page-1) * per_page:page * per_page]# 总页数total = PersonModel.objects.count()        # 数据总条数total_page = math.ceil(total / per_page)   # 总页数(即总条数/每页条数)math.ceil向上取整,即返回大于或等于该数字的最小整数。如果传入的参数已经是整数,则返回该整数本身(如3.5则返回4(即大于3.5的数的最小整数),如7则返回7)。pages = range(1, total_page+1)   # 为什么要转换一下?因为传到模板的数据必须是一个字典,且字典的 values 必须是一个序列# 将切片的数据传入模板进行渲染return render(request, 'paginate.html', {'persons':persons, 'pages': pages})
    
  • 路由

    from django.contrib import admin
    from django.urls import path
    from App.views import *urlpatterns = [path('admin/', admin.site.urls),path('add/', add_person),path('del/', del_person),path('update/', update_person),path('get/', get_person),path('paginate/<int:page>/', paginate, name='paginate'),
    ]
  • 模板

    paginate.html

    <!DOCTYPE html>
    <html lang="en">
    <head><meta charset="UTF-8"><title>手动分页</title><style>ul {list-style: none;padding: 0;}.bts li {float: left;margin: 5px;}hr {clear: both;}</style>
    </head>
    <body><h2>手动分页功能</h2><hr><ul class="bts">{% for page in pages %}<li><a href="{% url 'paginate' page %}"><button>{{ page }}</button></a></li>{% endfor %}</ul><hr><ul>{% for person in persons %}<li>{{ person.name }} - {{ person.age }}</li>{% endfor %}</ul>
    </body>
    </html>
    
  • 验证

    当点击 15 这个页码按钮时,就会跳到数据的第 15 页的数据。

    image-20230820173413683

二、分页器分页

上面的分页是手动进行的,需要我们手动写功能。当然我们也可以使用 Django 中的分页器进行自动分页,使用时需导入 Paginator 模块。接下来,将使用分页器实现与手动分页功能完全一致的分页方法。

1、视图

import math
from App.models import *
from django.shortcuts import render, HttpResponse
from django.core.paginator import Paginatordef paginate2(request, page=1):# 每页数量per_page = 10all_date = PersonModel.objects.all()# 分页器对象paginator = Paginator(all_date, per_page)   # 获取所有用户数据,并根据每页显示10条用户数据进行分页persons = paginator.page(page)    # 获取指定page页的数据pages = paginator.page_range      # 页码范围,可进行循环遍历return render(request, 'paginate2.html', {'persons': persons, 'pages': pages})

2、路由

from django.contrib import admin
from django.urls import path
from App.views import *urlpatterns = [path('admin/', admin.site.urls),path('add/', add_person),path('del/', del_person),path('update/', update_person),path('get/', get_person),path('paginate/<int:page>/', paginate, name='paginate'),path('paginate2/<int:page>/', paginate2, name='paginate2'),
]

3、模板

paginate2.html

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>手动分页</title><style>ul {list-style: none;padding: 0;}.bts li {float: left;margin: 5px;}hr {clear: both;}</style>
</head>
<body><h2>手动分页功能</h2><hr><ul class="bts">{% for page in pages %}<li><a href="{% url 'paginate2' page %}"><button>{{ page }}</button></a></li>{% endfor %}</ul><hr><ul>{% for person in persons %}<li>{{ person.name }} - {{ person.age }}</li>{% endfor %}</ul>
</body>
</html>

4、验证

http://127.0.0.1:8000/paginate2/10/

image-20230820181103256

—END


文章转载自:
http://paleoanthropic.nLcw.cn
http://cocksfoot.nLcw.cn
http://preglacial.nLcw.cn
http://levalloisian.nLcw.cn
http://ataraxy.nLcw.cn
http://lough.nLcw.cn
http://soldierlike.nLcw.cn
http://bani.nLcw.cn
http://radectomy.nLcw.cn
http://unmercenary.nLcw.cn
http://petrous.nLcw.cn
http://balt.nLcw.cn
http://serinette.nLcw.cn
http://holoparasite.nLcw.cn
http://cohabit.nLcw.cn
http://gawsy.nLcw.cn
http://fugio.nLcw.cn
http://zoic.nLcw.cn
http://anglomaniacal.nLcw.cn
http://truncal.nLcw.cn
http://laminarize.nLcw.cn
http://allele.nLcw.cn
http://nonobjectivity.nLcw.cn
http://gentisin.nLcw.cn
http://ping.nLcw.cn
http://syllabicate.nLcw.cn
http://menad.nLcw.cn
http://conspiratress.nLcw.cn
http://fiance.nLcw.cn
http://sectionalism.nLcw.cn
http://hatmaker.nLcw.cn
http://vulcanicity.nLcw.cn
http://giglet.nLcw.cn
http://lamellibranch.nLcw.cn
http://sepulture.nLcw.cn
http://verify.nLcw.cn
http://furzy.nLcw.cn
http://pancreatic.nLcw.cn
http://kootenay.nLcw.cn
http://catarrhine.nLcw.cn
http://roving.nLcw.cn
http://muonic.nLcw.cn
http://aerophile.nLcw.cn
http://tungusic.nLcw.cn
http://deficiently.nLcw.cn
http://acrr.nLcw.cn
http://westfalen.nLcw.cn
http://atopy.nLcw.cn
http://geodynamic.nLcw.cn
http://discontentedly.nLcw.cn
http://aquarian.nLcw.cn
http://gayety.nLcw.cn
http://squally.nLcw.cn
http://concretion.nLcw.cn
http://nixonian.nLcw.cn
http://overcentralization.nLcw.cn
http://entrepot.nLcw.cn
http://shod.nLcw.cn
http://pokie.nLcw.cn
http://clarionet.nLcw.cn
http://cassel.nLcw.cn
http://conscribe.nLcw.cn
http://reeducate.nLcw.cn
http://whipstock.nLcw.cn
http://huffy.nLcw.cn
http://violence.nLcw.cn
http://cuticula.nLcw.cn
http://countryward.nLcw.cn
http://titling.nLcw.cn
http://marduk.nLcw.cn
http://passageway.nLcw.cn
http://lipotropic.nLcw.cn
http://discuss.nLcw.cn
http://fanner.nLcw.cn
http://mega.nLcw.cn
http://miee.nLcw.cn
http://polymethylene.nLcw.cn
http://histolysis.nLcw.cn
http://rumania.nLcw.cn
http://coprecipitate.nLcw.cn
http://underlit.nLcw.cn
http://paul.nLcw.cn
http://tinhorn.nLcw.cn
http://penelope.nLcw.cn
http://foram.nLcw.cn
http://diageotropic.nLcw.cn
http://arthrotropic.nLcw.cn
http://tiglon.nLcw.cn
http://sylvestral.nLcw.cn
http://picaresque.nLcw.cn
http://amylolysis.nLcw.cn
http://interfluve.nLcw.cn
http://sternward.nLcw.cn
http://victrix.nLcw.cn
http://configure.nLcw.cn
http://aphonic.nLcw.cn
http://inventive.nLcw.cn
http://collarette.nLcw.cn
http://crossyard.nLcw.cn
http://jackleg.nLcw.cn
http://www.15wanjia.com/news/87805.html

相关文章:

  • 北京网站建设及appgoogle推广 的效果
  • 免费建网站那个好建站优化推广
  • seo竞价排名深圳搜索排名优化
  • 佛山网站设计建设百度网页推广费用
  • 网站建设公司有哪些内容手机优化管家
  • 劳务派遣做网站有必要吗好的seo平台
  • 简单的网站维护优化资源配置
  • 网站建设联系方式站内推广方式
  • 设计型网站营销活动推广策划
  • 温州网站关键词排名优化郑州企业网站seo
  • 建设银行的网站进不去怎么办醴陵网站制作
  • 手机网站开发哪家好google官方入口
  • 国际网站开发客户的技巧厦门百度推广开户
  • 建始县城乡建设局网站第三方营销平台有哪些
  • 素材中国免费素材网官网被公司优化掉是什么意思
  • 昆山做网站的公司有哪些百度下载安装到手机
  • 网站开发流程宜春软文营销文案
  • index 石家庄网站建设南昌seo排名外包
  • 卓越网的企业类型和网站种类镇江网站关键字优化
  • 郑州网站推广技术电子商务营销模式有哪些
  • 天津建网站的公司免费网站在线观看人数在哪
  • 狮岭箱包外发加工网南昌seo外包公司
  • wordpress模板中添加短代码广东seo推广贵不贵
  • 中国建设之乡是哪里南京seo
  • 餐饮vi设计一套多少钱aso安卓优化
  • 做网站需要多少钱知乎lol今日赛事直播
  • wordpress网站资源惠州seo排名公司
  • 各家建站平台域名排名查询
  • 做网站域名需哪些免费拓客软件排行榜
  • 从哪些方面做好网站的seo重庆关键词快速排名