zoukankan      html  css  js  c++  java
  • django查看数据库

    #views
    import pymysql
    def get_date(request):
        conn = pymysql.connect(
            host='localhost',
            port=3306,
            user='root',
            passwd='mysql',
            db='homework2',
            charset='utf8',
            autocommit=True
        )
        cursor = conn.cursor(pymysql.cursors.DictCursor)
        # sql = "select * from ?"
        # sql = sql.replace('%s','?')
        sql = "select * from teacher_info"
        # value = "teacher_info"
        # cursor.execute(sql,value)
        cursor.execute(sql)
        user_list = cursor.fetchall()
    
        with open(r'templates/get_data.html','r',encoding='utf8') as fr:
            data = fr.read()
        return render(request,'get_data.html',{'user_list':user_list})
    
    #html
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>get_data</title>
        <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
        <link href="https://cdn.bootcss.com/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
        <script src="https://cdn.bootcss.com/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
        <script src="https://use.fontawesome.com/aaee4b5d24.js"></script>
    </head>
    <body>
    <div class="container">
        <div class="row">
            <div class="col-md-8 col-md-offset-2">
                <h2 class="text-center">数据展示</h2>
                <table class="table table-striped table-bordered table-hover">
                    <thead>
                        <tr>
                            <th>id</th>
                            <th>name</th>
                            <th>age</th>
                            <th>salary</th>
                            <th>job</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for user in user_list %}
                            <tr>
                                <td>{{ user.id }}</td>
                                <td>{{ user.name }}</td>
                                <td>{{ user.age }}</td>
                                <td>{{ user.salary }}</td>
                                <td>{{ user.job }}</td>
                            </tr>
    
                        {% endfor %}
    
                    </tbody>
                </table>
            </div>
        </div>
    </div>
    
    </body>
    </html>
    
  • 相关阅读:
    第一章—v-text和v-html
    第一章—v-for
    第一章—v-show
    react_9
    【软件工程】
    【软件工程】网页设计基础 第一章
    【软件工程】psp四则运算
    【python】网络爬虫与信息提取
    【python】数据库学习笔记,设计自己的大学排名
    【python】用python玩微信跳一跳小游戏
  • 原文地址:https://www.cnblogs.com/agsol/p/11908419.html
Copyright © 2011-2022 走看看