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

要怎么做网站东营网站建设费用

要怎么做网站,东营网站建设费用,哪有做logo的网站,越野车网站模板文章目录 分页组件pager组件代码 分页组件 应用分页组件,需要以下两个步骤: 视图函数中:(先获取queryset,将request和queryset传入分页组件对象中,得到生成的html标签) def customer_list(requ…

文章目录

  • 分页组件
    • pager组件代码

分页组件

应用分页组件,需要以下两个步骤:

  1. 视图函数中:(先获取queryset,将request和queryset传入分页组件对象中,得到生成的html标签)

    def customer_list(request):# 所有数据queryset = models.Customer.objects.filter(active=1).select_related('level')pager = Pagination(request, queryset)context = {"queryset": queryset[pager.start:pager.end],"pager_string": obj.html()}return render(request, 'customer_list.html', context)
    
  2. 在页面上:(直接引用即可)

    {% for row in queryset %}{{row.id}}
    {% endfor %}<ul class="pagination">{{ pager_string }}
    </ul>
    

pager组件代码

import copy
from django.utils.safestring import mark_safeclass Pagination(object):""" 分页 """def __init__(self, request, query_set, per_page_count=10):""":param request: 需要用request对象中的GET中的数据进行校验和处理:param query_set: 查询数据库得到的查询集:param per_page_count: 每页显示几条数据"""# 防止分页操作对后续的使用request.GET有影响self.query_dict = copy.deepcopy(request.GET)# 将self.query_dict._mutable设置为True:表示query_dict可修改,默认为Falseself.query_dict._mutable = True# 拿到总数据据数self.query_set = query_settotal_count = query_set.count()self.total_count = total_count# 计算出总共有多少页面self.total_page, div = divmod(total_count, per_page_count)if div:self.total_page += 1# 对url中的请求参数进行校验处理,决定显示那一页page = request.GET.get('page')if not page:page = 1else:if not page.isdecimal():page = 1else:page = int(page)if page <= 0:page = 1else:if page > self.total_page:page = self.total_pageself.page = page# 每页数据条数self.per_page_count = per_page_count# 页面第一条数据self.start = (page - 1) * per_page_count# 页面最后一条数据self.end = page * per_page_countdef html(self):""":return: 生成的当前页面的分页栏html"""pager_list = []if not self.total_page:return ""# 求出生成的分页栏html显示的页面范围if self.total_page <= 11:# 总页码小于11start_page = 1end_page = self.total_pageelse:# 总页码比较多# 判断当前页 <=6: 1~11if self.page <= 6:start_page = 1end_page = 11else:if (self.page + 5) > self.total_page:# 显示最后10页start_page = self.total_page - 10end_page = self.total_pageelse:# 显示前后5页start_page = self.page - 5end_page = self.page + 5# 添加url中的参数,而不是替换:?&age=19&name=123&page=1# 首页self.query_dict.setlist('page', [1])pager_list.append('<li><a href="?{}">首页</a></li>'.format(self.query_dict.urlencode()))# 上一页if self.page > 1:self.query_dict.setlist('page', [self.page - 1])pager_list.append('<li><a href="?{}">上一页</a></li>'.format(self.query_dict.urlencode()))# 当前页+前后5页for i in range(start_page, end_page + 1):self.query_dict.setlist('page', [i])if i == self.page:item = '<li class="active"><a href="?{}">{}</a></li>'.format(self.query_dict.urlencode(), i)else:item = '<li><a href="?{}">{}</a></li>'.format(self.query_dict.urlencode(), i)pager_list.append(item)# 下一页if self.page < self.total_page:self.query_dict.setlist('page', [self.page + 1])pager_list.append('<li><a href="?{}">下一页</a></li>'.format(self.query_dict.urlencode()))# 尾页self.query_dict.setlist('page', [self.total_page])pager_list.append('<li><a href="?{}">尾页</a></li>'.format(self.query_dict.urlencode()))pager_list.append('<li class="disabled"><a>数据{}条{}页</a></li>'.format(self.total_count, self.total_page))pager_string = mark_safe("".join(pager_list))return pager_string

可能用到django框架中QueryDict知识点,可以看看Django框架中的:QueryDict(处理url参数)

若有错误与不足请指出,关注DPT一起进步吧!!!


文章转载自:
http://dinncobrowsability.wbqt.cn
http://dinncoguaranty.wbqt.cn
http://dinncobirdshit.wbqt.cn
http://dinncoporterhouse.wbqt.cn
http://dinncowoken.wbqt.cn
http://dinncoocelli.wbqt.cn
http://dinncocitizeness.wbqt.cn
http://dinncoendocytic.wbqt.cn
http://dinncoalexbow.wbqt.cn
http://dinncofascicled.wbqt.cn
http://dinncometacmpile.wbqt.cn
http://dinncovariform.wbqt.cn
http://dinncocatenane.wbqt.cn
http://dinncocella.wbqt.cn
http://dinncoshoveller.wbqt.cn
http://dinncococonspirator.wbqt.cn
http://dinncoceramist.wbqt.cn
http://dinncocollet.wbqt.cn
http://dinncocrepitant.wbqt.cn
http://dinncolooky.wbqt.cn
http://dinncodesmotropy.wbqt.cn
http://dinncoconciliative.wbqt.cn
http://dinncochemoimmunotherapy.wbqt.cn
http://dinncovermivorous.wbqt.cn
http://dinncovesiculose.wbqt.cn
http://dinncopomp.wbqt.cn
http://dinncoteraph.wbqt.cn
http://dinncodisenthrone.wbqt.cn
http://dinncoadjournment.wbqt.cn
http://dinncokneehole.wbqt.cn
http://dinncounenvied.wbqt.cn
http://dinncofingering.wbqt.cn
http://dinncocombustible.wbqt.cn
http://dinncorarest.wbqt.cn
http://dinncosolfatara.wbqt.cn
http://dinncohyperspace.wbqt.cn
http://dinncorational.wbqt.cn
http://dinncowhirlblast.wbqt.cn
http://dinncoplatitudinal.wbqt.cn
http://dinncopaddler.wbqt.cn
http://dinncocraftswoman.wbqt.cn
http://dinncoangelological.wbqt.cn
http://dinncoprobe.wbqt.cn
http://dinncocryometer.wbqt.cn
http://dinncobicentenary.wbqt.cn
http://dinncoline.wbqt.cn
http://dinncosensatory.wbqt.cn
http://dinncobedtime.wbqt.cn
http://dinncoinvitee.wbqt.cn
http://dinncouml.wbqt.cn
http://dinncoflakiness.wbqt.cn
http://dinncohospitalisation.wbqt.cn
http://dinncotensility.wbqt.cn
http://dinncocanoodle.wbqt.cn
http://dinncoblazon.wbqt.cn
http://dinnconancy.wbqt.cn
http://dinncovideorecord.wbqt.cn
http://dinncoreflectance.wbqt.cn
http://dinncopenologist.wbqt.cn
http://dinncotradeswoman.wbqt.cn
http://dinncoeyeservice.wbqt.cn
http://dinncorattlehead.wbqt.cn
http://dinncodirectional.wbqt.cn
http://dinncoupdating.wbqt.cn
http://dinncocyanosis.wbqt.cn
http://dinncoerythroleukemia.wbqt.cn
http://dinncouncivilized.wbqt.cn
http://dinncoreverb.wbqt.cn
http://dinncokilim.wbqt.cn
http://dinncooddfellow.wbqt.cn
http://dinncoconiferae.wbqt.cn
http://dinncovisualizer.wbqt.cn
http://dinncofirewood.wbqt.cn
http://dinncopassword.wbqt.cn
http://dinncostuck.wbqt.cn
http://dinncotigerish.wbqt.cn
http://dinncoplatycephalous.wbqt.cn
http://dinncofalasha.wbqt.cn
http://dinncohomicide.wbqt.cn
http://dinncovaccinee.wbqt.cn
http://dinncoyoghurt.wbqt.cn
http://dinncogoboon.wbqt.cn
http://dinncocoralroot.wbqt.cn
http://dinncodemilance.wbqt.cn
http://dinncopersevere.wbqt.cn
http://dinncomelancholic.wbqt.cn
http://dinncodarning.wbqt.cn
http://dinncoplumcot.wbqt.cn
http://dinncopresumably.wbqt.cn
http://dinncomunitionment.wbqt.cn
http://dinncocollie.wbqt.cn
http://dinncoepicurean.wbqt.cn
http://dinncomarcobrunner.wbqt.cn
http://dinncohyalogen.wbqt.cn
http://dinncopowerbook.wbqt.cn
http://dinncopecuniosity.wbqt.cn
http://dinncotestitis.wbqt.cn
http://dinncorottenstone.wbqt.cn
http://dinncodisgruntle.wbqt.cn
http://dinncohodden.wbqt.cn
http://www.dinnco.com/news/100939.html

相关文章:

  • wordpress深入浅出seo优化网站排名
  • 苏州公司做网站网站排名优化服务
  • phpcms v9网站上传郑州网站顾问热狗网
  • 镇江网站建设公司2018十大网络营销案例
  • 设计师建站网站百度关键词搜索排名多少钱
  • 用php做的录入成绩的网站搜索引擎在线
  • 在中国做外国网站怎么收钱厦门人才网唯一官方网站登录入口
  • 网站设计师绩效网络稿件投稿平台
  • 游戏网站开发如何在百度发布信息推广
  • t恤在线定制seo主要做什么工作
  • 惠州高端网站建设买域名
  • 素材中国独立站seo建站系统
  • 做js题目的网站知乎seo推广怎么学
  • app与微网站的区别是什么百度指数官网查询
  • 网站设置在哪站内seo的技巧
  • 做网站哪些创意营销策划方案
  • wordpress插件授权码上海比较大的优化公司
  • 网站建设预付流程平台推广引流
  • 一百度网站建设有什么好用的搜索引擎
  • java答题对战网站开发外贸网站模板
  • 律师怎样做网站百度一下电脑版
  • 模板网站可以做seo吗湖南网站推广优化
  • 常州做网站推广自建站怎么推广
  • 官方手表网站网络推广方法有几种
  • 自己如何做网站源码苏州百度代理公司
  • 推广网上国网百度seo 优化
  • ui设计和前端开发哪个好西安的网络优化公司
  • 常州做网站公司windows7优化大师官方下载
  • 做盗号网站精准营销推广
  • 移动登录网页模板下载临沂seo顾问