#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>

django查看数据库的更多相关文章

  1. django 操作数据库--orm(object relation mapping)---models

    思想 django为使用一种新的方式,即:关系对象映射(Object Relational Mapping,简称ORM). PHP:activerecord Java:Hibernate C#:Ent ...

  2. Django模型-数据库操作

    前言 前边记录的URLconf和Django模板全都是介绍页面展示的东西,也就是表现层的内容.由于Python先天具备简单而强大的数据库查询执行方法,Django 非常适合开发数据库驱动网站. 这篇开 ...

  3. Django: 之数据库导入、迁移和联用

    Django 数据库导入 从网上下载的一些数据,excel表格,xml文件,txt文件等有时候我们想把它导入数据库,应该如何操作呢? 以下操作符合 Django版本为 1.6 ,兼顾 Django 1 ...

  4. Django查询数据库性能优化

    现在有一张记录用户信息的UserInfo数据表,表中记录了10个用户的姓名,呢称,年龄,工作等信息. models文件 from django.db import models class Job(m ...

  5. python:前端(HTML)+后端(Django)+数据库(MySQL)

    1.创建一个html文件用于简单的网页注册demo <!DOCTYPE html> <html lang="en"> <head> <me ...

  6. 如何使用django操作数据库,向原有表中添加新的字段信息并建立一个多对多的关系?

    (注:本人用的pycharm开发工具) 1.在你要添加新字段的app的 models.py 文件中添加需要新增的字段(book表新增authors字段并和author建立多对多关系,author表新增 ...

  7. 第一篇-Django建立数据库各表之间的联系(上)

    多表操作(一对多) 遇到的问题: 执行python manage.py makemigrations后报如下错误 TypeError: __init__() missing 1 required po ...

  8. Django 2.0 学习(16):Django ORM 数据库操作(下)

    Django ORM数据库操作(下) 一.增加表记录 对于表单有两种方式: # 方式一:实例化对象就是一条表记录france_obj = models.Student(name="海地&qu ...

  9. Django 2.0 学习(14):Django ORM 数据库操作(上)

    Django ORM 数据库操作(上) ORM介绍 映射关系: 数据库表名 ---------->类名:数据库字段 ---------->类属性:数据库表一行数据 ----------&g ...

随机推荐

  1. leyou_02_nginx使用域名访问本地项目

    1.nginx的搭建依赖环境 1.1 准备jdk环境 当前最新版本下载地址:http://www.oracle.com/technetwork/java/javase/downloads/index. ...

  2. Interface Builder: What are the UIView's Layout iOS 6/7 Deltas for?

    up vote57down votefavorite 19 I just noticed the iOS 6/7 Delta property found under the UIView's str ...

  3. 499 单词计数 (Map Reduce版本)

    原题网址:https://www.lintcode.com/problem/word-count-map-reduce/description 描述 使用 map reduce 来计算单词频率http ...

  4. jeecmsv9-adminVue 打包出错

    F:\jeecms\jeecmsv9-adminVue>node build\build.js - building for production...Error processing file ...

  5. JSP页面格式化timestamp时间

    timestamp类型返回并直接取值显示会带小尾巴 偶然发现 <fmt:formatDate value="${order.createTime}" type="b ...

  6. spring boot 源码解析11-ConfigurationClassPostProcessor类加载解析

    前言 ConfigurationClassPostProcessor实现了BeanDefinitionRegistryPostProcessor接口,该类会在AbstractApplicationCo ...

  7. Jmeter环境搭建及目录介绍

    Jmeter环境搭建及目录介绍 运行环境:jmeter是基于java语言的,所有需要准备Java的JDK环境,并添加到环境变量中. 一.环境搭建及配置 1.JMeter的下载: 官网:http://j ...

  8. css3之 渐变

    CSS3 渐变(gradients)可以让你在两个或多个指定的颜色之间显示平稳的过渡. 以前,你必须使用图像来实现这些效果.但是,通过使用 CSS3 渐变(gradients),你可以减少下载的事件和 ...

  9. Xcode10 代码块(Code Snippet)添加和删除

    https://blog.csdn.net/lg767201403/article/details/82761448 Code Snippets 使用 https://blog.csdn.net/lv ...

  10. linux 修改命令提示符&ubuntu目录颜色个性化

    1.linux 命令提示符个性化 在 ANSI 兼容终端(例如 xterm.rxvt.konsole 等)里, 可以用彩色显示文本而不仅仅是黑白. 本文示范了如何使用粗体和彩色的文字.     相信每 ...