zoukankan      html  css  js  c++  java
  • [oldboy-django][2深入django]学生管理(Form)--查看(分页)

    1 需求: 查看所有学生的信息,(分页功能)

    2 前端:bootstrap美化前端

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <link rel="stylesheet" href="/static/plugins/bootstrap-3.3.7-dist/css/bootstrap.css">
        <link rel="stylesheet" href="/static/plugins/font-awesome-4.7.0/css/font-awesome.css">
    </head>
    <body>
    <h4>学生管理</h4>
            <p>
                <a href="/app01/add_student"  class="btn btn-primary">添加</a>
            </p>
            <table class="table table-striped table-bordered table-hover table-condensed">
                <thead>
                    <tr>
                        <th>ID</th>
                        <th>姓名</th>
                        <th>年龄</th>
                        <th>邮箱</th>
                        <th>班级</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    {% for item in student_list %}
                        <tr>
                            <td>{{ item.id }}</td>
                            <td>{{ item.name }}</td>
                            <td>{{ item.age }}</td>
                            <td>{{ item.email }}</td>
                            <td>{{ item.cls_id }}</td>
                            <td>
                                <a href="/app01/edit_student/nid={{ item.id }}" class="glyphicon glyphicon-pencil">编辑</a>|
                                <a href="/app01/del_student/nid={{ item.id }}" class="glyphicon glyphicon-trash">删除</a>
                            </td>
                            {#点击删除是一个get请求,要想告诉服务器id,可以通过url get请求获取,或者url匹配到传递给视图#}
                        </tr>
                    {% endfor %}
    
                </tbody>
            </table>
            <nav aria-label="Page navigation">
                <ul class="pagination">
                    {{ page_info.pager|safe }}
                </ul>
            </nav>
    </body>
    </html>
    View Code

    3 视图

    def students(request):
        from utils.pagation_define import PageInfo
        current_page_number = request.GET.get('page')
        all_count = models.Classes.objects.all().count()
        page_info = PageInfo(current_page_number, all_count, "/app01/students")
        stu_list = models.Student.objects.all()[page_info.start():page_info.end()]
        return render(request, 'app01_student_list.html', {'student_list': stu_list})
    View Code

     

  • 相关阅读:
    Spark Streaming 中管理 Kafka Offsets 的几种方式
    Kafka 在华泰证券的探索与实践
    Kafka 客户端是如何找到 leader 分区的
    关于Java中如何判断字符串是否为json格式
    关于JAVA递归遍历树级菜单结构
    关于JDK8 三种时间获取方法以及日期加减
    关于在Java里面,时间的一些业务
    关于Java的IO通信
    关于git同时提交到2个仓库gitee github
    关于JVM——工具(二)
  • 原文地址:https://www.cnblogs.com/liuzhipenglove/p/7873351.html
Copyright © 2011-2022 走看看