首页 > 代码库 > Django自带分页功能
Django自带分页功能
直接上代码:
models.py
django.db models Asset(models.Model): OS_CHOICE = [ (, ), (, ), (, ), (, ), (, ), ] hostname = models.CharField(=, =, =) ip = models.GenericIPAddressField(=, =) port = models.IntegerField(=, =) username = models.CharField(=, =) password = models.CharField(=, =) os = models.CharField(=OS_CHOICE, =, =, =) is_active = models.BooleanField(=, =) (): .hostname
views.py
django.shortcuts get_object_or_404,render django.http HttpResponse django.views.generic ListView, CreateView, DetailView, View, UpdateView django.urls reverse_lazy django.core.paginator Paginator,EmptyPage,PageNotAnInteger .forms AssetForm .models Asset users.mixins LoginRequiredMixin page_list(request): assets = Asset.objects.all() paginator = Paginator(assets,) page = request.GET.get() page: article_list = paginator.page(page).object_list : article_list = paginator.page().object_list : customer = paginator.page(page) PageNotAnInteger: customer = paginator.page() EmptyPage: customer = paginator.page(paginator.num_pages) render(request,,{:customer,:article_list})
template模板
主机名 IP 端口 管理账号 系统 Active 操作 {% for asset in articles %} {{ asset.hostname }} {{ asset.ip }} {{ asset.port }} {{ asset.username }} {{ asset.get_os_display }} {% if not user.is_active %} 否 {% else %} {% endif %} {% endfor %} {% if cus_list.has_previous %} {% endif %} {% for pg in cus_list.paginator.page_range %} {% if cus_list.number == pg %} {{ pg }}{% else %} {{ pg }}j8-3 {% endif %} {% endfor %} {% if cus_list.has_next %} {% endif %}
效果如图:
本文出自 “13010688” 博客,请务必保留此出处http://13020688.blog.51cto.com/13010688/1950482
Django自带分页功能
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。