CSS Ribbon

Reproducing the GitHub Ribbon in CSS

路飞学城Python-Day108

96-分页器1
批量插入的方式就不能用ORM的create()方式去做了,因为create就是对sql进行insert的操作,sql最好不要每次有一条数据就去进行插入,最好的方式就是插入一组数据
复制代码
from django.shortcuts import render
from django.core.paginator import Paginator, EmptyPage
# Create your views here.
from app01.models import Book


def index(request):
    '''

    :param request:
    :return:
    '''
    # book_list = []
    # for i in range(100):
    #     book_obj = Book(title="book_%s" % i, price=i*i)
    #     book_list.append(book_obj)
    # #     进行批量插入
    # Book.objects.bulk_create(book_list)
    book_list = Book.objects.all()
    paginator = Paginator(book_list, 10)
    # print(paginator.count)
    # print(paginator.num_pages)
    try:
        c_page = int(request.GET.get('page', 1))
        c_page = paginator.page(c_page)
        # print(page1.object_list)
        for i in c_page:
            print(i.title)
    except EmptyPage as e:
        c_page = paginator.page(1)
    return render(request, 'index.html', locals())
View Code
复制代码
复制代码
from django.db import models

# Create your models here.


class Book(models.Model):
    title = models.CharField(max_length=32)
    price = models.DecimalField(decimal_places=2, max_digits=8)
models.py
复制代码
复制代码
"""PageDemo URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/2.1/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from app01 import views
urlpatterns = [
    path('admin/', admin.site.urls),
    path('index/', views.index),
]
urls.py
复制代码
复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>分页器</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>
<body>
    <ul>
        {% for book in c_page %}
            <li>
            {{ book.title }}:{{ book.price }}
            </li>
        {% endfor %}
    </ul>
<nav aria-label="Page navigation">
  <ul class="pagination">

        {% if c_page.has_previous%}
            <li>
            <a href="?page={{ c_page.previous_page_number }}" aria-label="Previous">
        <span aria-hidden="true">上一页</span>
        </a>
            </li>
            {% else %}
             <li class="disabled">
            <a href="" aria-label="Previous">
        <span aria-hidden="true">上一页</span>
        </a>
            </li>
        {% endif %}


        {% for foo in page_range %}
            {% if c_page_n == foo %}
                <li class="active"><a href="?page={{ foo }}">{{ foo }}</a></li>
                {% else %}
                 <li><a href="?page={{ foo }}">{{ foo }}</a></li>
            {% endif %}

        {% endfor %}

        {% if c_page.has_next %}
             <li>
            <a href="?page={{ c_page.next_page_number }}" aria-label="Next">
        <span aria-hidden="true">下一页</span>
        </a>
             </li>
            {% else %}
            <li class="disabled">
             <a href="" aria-label="Next">
        <span aria-hidden="true">下一页</span>
        </a>
             </li>
        {% endif %}


  </ul>
</nav>

</body>
</html>
index.html
复制代码
97-分页器2
98-分页器3
99-分页器4

posted on   pandaboy1123  阅读(194)  评论(0编辑  收藏  举报

编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示