web 框架 Django 学习记录 (二)把数据库中表内容展示在页面
2017-07-03 19:13
701 查看
1.创建项目、应用
2.修改配置
修改yu1\yu1\settings.py文件
INSTALLED_APPS ,添加一行 ‘yuApp’,
TEMPLATES ,修改’DIRS’: [BASE_DIR+”/templates”,],
3.修改 yu1\yu1\urls.py 文件
4.修改yu1\yuApp\views.py
5.新建文件\yu1\templates\order_list.html
写入内容
6.启动服务
python manage.py runserver 0.0.0.0:8000
7.浏览器输入 127.0.0.1:8000/order
即可看到数据
django-admin startproject yu1 cd yu1 python manage.py startapp yuApp
2.修改配置
修改yu1\yu1\settings.py文件
INSTALLED_APPS ,添加一行 ‘yuApp’,
TEMPLATES ,修改’DIRS’: [BASE_DIR+”/templates”,],
3.修改 yu1\yu1\urls.py 文件
from yuApp import views urlpatterns 添加一行 url(r'^order$',views.order),
4.修改yu1\yuApp\views.py
from django.shortcuts import render import MySQLdb def get_data(sql):#获取数据库的数据 conn = MySQLdb.connect(conf.test_dbhost,conf.test_user,conf.test_passd,conf.test_dbname,port=8306,charset="utf8") cur = conn.cursor() cur.execute(sql) results = cur.fetchall() # 搜取所有结果 cur.close() conn.close() return results def order(request):# 向页面输出订单 sql = "SELECT order_sn,shop_sn,accept_name,address,org_price,allprice,voucher " \ "FROM `tb_order` ORDER BY order_id DESC LIMIT 50" m_data = get_data(sql) return render(request,'order_list.html',{'order':m_data})
5.新建文件\yu1\templates\order_list.html
写入内容
<html> <head> <title>订单查询</title> </head> <body> <B>订单展示</B> <br> <table border="1"> <tr> <th>序号</th> <th>订单编号</th> <th>门店编号</th> <th>收货人</th> <th>详细地址</th> <th>订单总价</th> <th>实付金额</th> <th>入机状态</th> </tr> {% for i in order %} <tr> <td>{{ forloop.counter }}</td> <td>{{ i.0 }}</td> <td>{{ i.1 }}</td> <td>{{ i.2 }}</td> <td>{{ i.3 }}</td> <td>{{ i.4 }}</td> <td>{{ i.5 }}</td> <td>{{ i.6 }}</td> </tr> {% endfor %} </table> </body> </html>
6.启动服务
python manage.py runserver 0.0.0.0:8000
7.浏览器输入 127.0.0.1:8000/order
即可看到数据
相关文章推荐
- Yaws(erlang web服务器框架) 学习记录之使用自定义函数输出WEB页内容
- django学习记录,动态web页面尝试
- web 框架 Django 学习记录 (三)一个实例
- Django在web页面展示linux服务器的文本内容
- web 框架 Django 学习记录(一)安装部署
- python web框架Django学习(六)数据库
- 简单学习Python的web框架Django(一)
- 一步步学习微软InfoPath2010和SP2010--第十三章节--SharePoint视图和仪表板(10)--仪表板页面和内容查询Web部件
- 将数据库中内容展示在前台页面上
- 一步步学习SPD2010--第十三章节--管理SP Server环境的Web内容(7)--批准页面布局
- 一步步学习SPD2010--第十三章节--管理SP Server环境的Web内容(8)--还原页面布局的早期版本
- 一步步学习SPD2010--第十三章节--管理SP Server环境的Web内容(5)--修改页面布局
- SSH三大框架CRUD项目中为什么会出现web页面页面数据出现修改,但是数据库里面的数据却没有修改
- python Web框架 Django学习(1)
- 一步步学习SPD2010--第十三章节--管理SP Server环境的Web内容(8)--还原页面布局的早期版本
- python Web框架 Django学习(4) API
- [转]Django 是一个 Python 下的 web 开发框架[学习资料]
- CodeIgniter web框架学习(1)-- view、controller之间的关系,及静态页面的加载实例
- 一步步学习SPD2010--第十三章节--管理SP Server环境的Web内容(4)--创建页面布局
- python Web框架 Django学习(3)