我是靠谱客的博主 甜美小刺猬,这篇文章主要介绍Flask框架,现在分享给大家,希望可以做个参考。

微框架、轻量级框架不比Django框架那种重量级框架体型臃肿,内容封装的比较全使用的时候好多可以直接调用,需要代码量较少,
Flask框架属于轻型框架,使用时所需代码量较多,用起来稍微麻烦一点
Flask框架pip下载就ok了

1. 最简单的flask程序

复制代码
1
2
3
4
5
6
7
8
from flask import Flask app = Flask(__name__) @app.route('/') #装饰器 def hello_world(): return 'Hello World!' if __name__ == '__main__': app.run()

在这里插入图片描述在这里插入图片描述
在这里插入图片描述
在这里插入图片描述找不到路径的问题
在这里插入图片描述
更改代码 debug 后,不需要重新运行就可以跳转页面:
在这里插入图片描述
在这里插入图片描述
flask访问服务器的端口号是 5000 ,flask框架的服务server是内置的

2. 调试模式

复制代码
1
2
3
app.run(debug=True) app.debug = True

3. 外部访问

复制代码
1
2
host = '0.0.0.0'

4. 路由

复制代码
1
2
3
4
5
6
7
@app.route( ' / ' ) def index(): return 'index Page' @app.route('/hello') def hello(): return 'Hello World'

5. 变量规则

要给URL添加变量部分,可以把特殊字段标记为<variable_name>,这部分将会作为命令参数传递到函数。规则可以用converter:variable_name指定一个可选的转换器

复制代码
1
2
3
4
5
6
7
@app.route('/user/<username>') def show_user_profile(username): return 'User %s' % username @app.route('/post/<int:post_id>') def show_post(post_id) return 'Post %d' post_id

在这里插入图片描述
在这里插入图片描述

复制代码
1
2
3
4
5
6
7
@app.route("/user/<username>") def show_user_profile(username): return "User %s" % username @app.route("/post/<int:post_id>") def show_post(post_id): return "Post %d" % post_id

在这里插入图片描述
可以转类型,三个类型 int 、 float 、path

6. 唯一URL/重定向行为:

带斜线 ( /…/ )重定向,不带斜线 ( /…) 是唯一
Flask的URL规则都基于Werkzeug的路由模块。这个模块背后的思想是基于Apache以及更早的HTTP服务器主张的先例,保证优雅且唯一的URL

复制代码
1
2
3
4
5
6
7
8
9
@app.route(' /projects/ ') def projects(): return 'The project page' @app.route('/about') def about(): return 'The about page'

7. 构造URL

flask能匹配URL, Flask也可以生成它们,可以用 url_for() 来给指定的函数构造URL。它接受函数名作为第一参数,也接受对应URL规则的变量部分的命名参数。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
from flask import Flask,url_for app = Flask(__name__) @app.route("/") def index(): pass @app.route("/user/<username>") def profile(username):pass with app.test_request_context(): print url_for('index') print url_for('login') print url_for('login',next='/') print url_for('profile',username='John Doe')

8. HTTP方法

复制代码
1
2
3
4
5
6
7
@app.route('/login', methods=['GET','POST']) def login(): if request.method == 'POST': do_the_login() else: show_the_login_form()

1/ get方式
传值的时候会暴露传输参数
参数大小有限制

2/ post方式
传值的时候不会暴露传输参数
参数大小没有限制

上面两种方式从不同的角度看,对比一下可以看出区别。

数据角度来看,两者一样;
安全角度来看,可以加密

9. 静态文件

10. 模板渲染

复制代码
1
2
3
4
5
6
from flask import render_template @app.route('/hello/') @app.route('/hello/<name>') def hello(name=None): return render_template('hello.html', name=name)

11. 文件上传

index.html:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body > <form action="/login" method="post"> 用户名:<input type="text" name="username" value=""> 密码:<input type="password" name="password"> <input type="submit" value="提交"> </form> <p style="color: red">{{error}}</p>

在这里插入图片描述
success.html :

复制代码
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
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <script src="/static/jquery-1.11.3.js"></script> <script src="/static/jquery.form.js"></script> <script> function upload() { var options = { type:"post", dataType:"text", success:function (data) { $('#img').attr("src",data); } } $('#jvForm').ajaxSubmit(options); } </script> </head> <body> <h1>登录成功,欢迎{{username}}</h1> <form action="/upload/" method="post" enctype="multipart/form-data" id="jvForm"> <input type="file" name="file" onchange="upload()"> <!--<input type="submit" value="上传">--> </form> <img src="" id="img"> </body> </html>

在这里插入图片描述

page_not_found.html:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> 这是一个错误页面 404 </body> </html>

在这里插入图片描述

12. Cookies

通过cookies属性来访问Cookies, 用影响对象的 set_cookie方法 来设置Cookies 。请求对象的 cookies属性 是一个内容为 客户端提交的所有Cookies的字典。

读取cookies:

复制代码
1
2
3
4
5
from flask import request @app.route('/') def index(): username = request.cookies.get('username')

存储cookies:

复制代码
1
2
3
4
5
6
7
from flask import make_response @app.route('/') def index(): resp = make_response(render_template(...)) resp.set_cookie('username', 'the username') return resp

13. 重定向(redirect)和错误

可以用 redirect( )函数 把用户重定向到其它地方。放弃请求并返回错误代码,用 abort()函数 。这里是一个它们如何使用的例子:

复制代码
1
2
3
4
5
6
7
8
9
10
from flask import abort, redirect, url_for @app.route('/') def index(): return redirect(url_for('login')) @app.route('/login') def login(): abort(401) this_is_never_executed() # 不可执行

这是一个相当无意义的例子,因为用户会从主页面重定向到一个不能访问的页面(401意味着禁止访问),但是它展示了重定向是如何工作的。

默认情况下,错误代码会显示一个黑白的错误页面。如果你要定制错误页面,可以使用 errorhandler()装饰器

复制代码
1
2
3
4
5
from flask import render_template @app.errorhandler(404) def page_not_found(error): return render_template('page_not_found.html'),404

注意render_template()调用之后的404,这告诉Flask,该页的错误代码是404,即没有找到。默认为200,也就是一切正常。
在这里插入图片描述

14. 会话 session

除请求对象外,还有一个 session对象。它允许你在不同请求间存储信息。它是在 Cookies的基础上实现的,并且对Cookies进行密钥签名。以查看你Cookie的内容,但却不能修改它,除非用户知道签名的密钥。

要使用会话,你需要设置一个密钥。这里介绍会话如何工作:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from flask import Flask, session, redirect, url_for, escape, request app = Flask(__name__) @app.route('/') def index(): if 'username' in session: # 如果username在session中 return 'Logged in as %s' % escape(session['username']) # 如果在就返回一个字符串 return 'You are not logged in' @app.route('/login',methods=['GET','POST']) def login(): if request.method == ‘POST’: # 判断 session['username']=request.form['username'] return redirect(url_for('index')) return .... @app.route('/logout') def logout(): session.pop('username',None) return redirect(url_for('index')) app.secret_key = ' A0Zr98j/3yX R~XHH!jmN]LWX/,?RT'

flask_demo.py:

复制代码
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
32
33
34
35
36
37
38
39
40
41
42
from flask import Flask,url_for,render_template,request,make_response,redirect,abort app = Flask(__name__) @app.route("/") def hello(): return redirect("/asd") @app.route("/asd") def hello1(): abort(404) @app.errorhandler(404) def page_not_found(error): return render_template('page_not_found.html'), 404 #跳转到index.html 登陆页面 @app.route("/index/") def hello_word(): username = request.cookies.get("username") if username==None: username="" return render_template("index.html",username=username) #接收参数 验证登录 @app.route("/login/",methods=["GET","POST"]) def login(): username = request.args.get("username") password = request.args.get("password") if username=="admin" and password=="123" : resp = make_response(render_template("success.html",username=username)) resp.set_cookie('username', "admin") return resp return render_template("index.html",error="*用户名或密码错误!!!") #文件上传 @app.route("/upload/",methods=['GET','POST']) def upload(): f = request.files["file"] f.save("static/HeadAttack0.gif") return "/static/HeadAttack0.gif" if __name__=='__main__': with app.test_request_context(): print(url_for('hello_word',name = "asd")) app.debug = True app.run(host='0.0.0.0')

login.py:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from flask import Flask,url_for,render_template,request,make_response,redirect,abort,session,escape,flash app = Flask(__name__) @app.route("/") def index(): if 'username' in session: return session['username'] flash('You were successfully logged in') return 'You are not logged in' @app.route("/index1") def index1(): return render_template("index.html") @app.route("/login" ,methods=['GET','POST']) def login(): username = request.form["username"] password = request.form["password"] if username=="admin" and password=="123": session["username"] = username return redirect("/") app.secret_key = 'A0Zr98j/3yX R~XHH!jmN]LWX/,?RT' app.run()

‘’’

二、Flask连接MySQL数据库:

Flask 用 Flask-SQLAlchemy 连接 MySQL

复制代码
1
2
安装: pip install Flask-SQLAlchemy

测试环境目录结构
在这里插入图片描述
上图是Flask做工程的基本文档结构,最上面 “ttt” 是工程名,其次下面的“ttt”是文件名,
Python3.0版本以后,

复制代码
1
2
3
4
5
6
7
8
__init__.py 可以不写了; creat_tables.py 是创建表的; models.py 是模型,这里面写的东西,是和创建的表里面写的东西是一一对应关系; 外层还有一个 manage.py 是做管理的,一定要注意这个文件是和文件名“ttt”是同级的! 还有一个 settings.py 是做设置的

settings.py :

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
DIALECT = 'mysql' DRIVER = 'pymysql' USERNAME = 'root' PASSWORD = '808069' HOST = '127.0.0.1' PORT = '3306' DATABASE = 'cms' SQLALCHEMY_DATABASE_URI = '{}+{}://{}:{}@{}:{}/{}?charset=utf8'.format( DIALECT,DRIVER,USERNAME,PASSWORD,HOST,PORT,DATABASE ) SQLALCHEMY_COMMIT_ON_TEARDOWN = True SQLALCHEMY_TRACK_MODIFICATIONS = True SQLALCHEMY_POOL_SIZE = 10 SQLALCHEMY_MAX_OVERFLOW = 5

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
__init__.py: (文件“ttt”导包的时候会自动运行这个) from flask_sqlalchemy import SQLAlchemy from flask import Flask # 导入Flask后,下面创建app db = SQLAlchemy() def create_app(): # 创建app对象 app = Flask(__name__) app.config.from_object('settings') # 这是从settings加载配置文件,settings里的设置是连接数据库用的,所以读到app去 db = SQLAlchemy() # 创建了一个db对象 db.init_app(app) # 用app里读到的一些参数,来初始化 return app

manage.py :

复制代码
1
2
3
4
5
6
from ttt import create_app app = create_app() if __name__ == '__main__': app.run() # 跑起来

models.py :

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
from manage import db class User(db.Model): # 类 __tablename__ = 'user' # 用户 # 下面有三列:id username password id = db.Column(db.INTEGER,primary_key=True) username = db.Column(db.String(80),unique=True) password = db.Column(db.String(80),nullable=False) class CodeCountRecord(db.Model): __tablename = 'codecountrecord' # 下面4列 id = db.Column(db.INTEGER,primary_key=True) count = db.Column(db.INTEGER) data = db.Column(db.DATE) user = db.Column(db.ForeignKey('user.id'))

create_tables.py :

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
from ttt import db, create_app from ttt.models import * # 导入models里所有的类 app = create_app() app_ctx = app.app_context() # app_ctx = app/g 加载连接数据库 with app_ctx: # __enter__,通过LocalStack放入Local中 db.create_all() # 调用LocalStack放入Local中获取app,再去app中获取配置

这种方式即为 离线脚本(不用启动项目)的方式创建数据库

直接右键运行 models.py 即可创建表
在这里插入图片描述

操作:

增:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
from cms.models import User from manage import db def create_user(): # 创建一个新用户对象 user = User() user.username = 'fuyong' user.password = '123' # 将新创建的用户添加到数据库会话中 db.session.add(user) # 将数据库会话中的变动提交到数据库中, 记住, 如果不 commit, 数据库中是没有变化的. db.session.commit() create_user()

删:

复制代码
1
2
3
4
5
6
7
8
9
10
def delete_user(): # 获取用户对象 user = User.query.filter_by(id=1).first() # 删除用户 db.session.delete(user) # 这个user里只包含id就可以了 #提交数据库会话 db.session.commit() delete_user()

改:

复制代码
1
2
3
4
5
6
7
8
9
def update_user(): # 获取用户对象 user = User.query.filter_by(id=2).first() # 修改用户 user.password = '123567' # 提交数据库会话 db.session.commit() update_user()

查:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
def select_user(): # 查询所有用户 users_list = User.query.all() # 查询用户名称为 fuyong 的第一个用户, 并返回用户实例, 因为之前定义数据库的时候定义用户名称唯一, 所以数据库中用户名称为 test 的应该只有一个. user = User.query.filter_by(username='fuyong').first() # or user = User.query.filter(User.username == 'fuyong').first() # 模糊查询, 查找用户名以abc 结尾的所有用户 users_list = User.query.filter(User.username.endsWith('g')).all() # 查询用户名不是 fuyong 的第一个用户 user = User.query.filter(User.username != 'fuyong').first()

循环导入的问题:

如果上面的例子继续写下去的时候,我们或许会在 视图views 中 引入models文件 以操作数据,
在models文件中引入manage文件中的db以定义类和字段,
然后在manage文件中引入views文件以注册蓝图(register_blueprint),
这样就出现了 a引入b,b引入c,c引入a的问题,就会报错,

解决办法就是另外创建一个 ext.py文件,专门用来创建db,代码如下:

复制代码
1
2
3
from flask_sqlalchemy import SQLAlchemy db = SQLAlchemy()

注意:此时先不讲app传入

然后在 manage.py 文件中,导入db,然后初始化,将app传进去:

复制代码
1
2
db.init_app(app)

这样,在视图中需要用db的之后直接从ext导入,而不再从manage里导入

三、Flask点餐系统

demo:

1.可研分析;2.需求分析;3.系统设计(概要设计 详细设计);4.编码;5.测试;6.实施运维;7.项目结束
在这里插入图片描述

用户表:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
id 姓名 证件类型 证件号码 电话 性别 照片 住址 出生日期 职业 是否黑名单 密码 级别 状态 备用1 ...

商家:

复制代码
1
2
3
4
5
6
7
8
9
id 名称 法人 电话 法人证件类型 证件号码 营业执照号码 附件(可以存多个照片) 地址

餐品管理:

复制代码
1
2
3
4
5
6
7
8
9
id 名称 价格 推荐 热卖 上架/下架 状态 新品

订单:

复制代码
1
2
3
4
5
6
7
8
9
订单id 商家id 用户id 菜品ids 单价 个数 总价 状态

配送:

复制代码
1
2
3
4
5
6
7
8
9
10
id 订单id 配送员id 商家id 用户id 配送地址 电话 时间 预计到达时间 配送状态(配送完成/配送中)

配送员:

复制代码
1
2
3
4
5
6
7
8
9
10
id 出生日期 姓名 性别 证件号码 电话 级别 负责区域 状态(美团这边删配送员不是真删,就好像淘宝删三鹿奶粉不是真删,只是下架了)

评论:

复制代码
1
2
3
4
5
6
7
id 商家id 用户id 内容 时间 状态

在这里插入图片描述

demo:

复制代码
1
2
3
4
5
6
7
8
9
10
11
__init__.py: from flask_sqlalchemy import SQLAlchemy from flask import Flask db = SQLAlchemy() def create_app(): app = Flask(__name__) app.config.from_object('settings') db = SQLAlchemy() db.init_app(app) return app

creat_tables.py:

复制代码
1
2
3
4
5
6
7
8
9
10
from demo import db, create_app from demo.models import * app = create_app() app_ctx = app.app_context() # app_ctx = app/g with app_ctx: # __enter__,通过LocalStack放入Local中 db.create_all() # 调用LocalStack放入Local中获取app,再去app中获取配置

models.py:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
from demo import db class Business(db.Model): __tablename__ = 'business' id = db.Column(db.INTEGER, primary_key=True) bname = db.Column(db.String(80), unique=True ,nullable=False) corporate = db.Column(db.String(80), nullable=False) tel = db.Column(db.String(80), nullable=False) idtype = db.Column(db.String(80), nullable=False) idnum = db.Column(db.String(80), nullable=False) licensenum = db.Column(db.String(80), nullable=False) imgs = db.Column(db.String(80), nullable=False) address = db.Column(db.String(80), nullable=False) state = db.Column(db.String(80), nullable=False)

manage.py

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
from demo import create_app , db from demo.models import User app = create_app() @app.route("/") def index(): user = User() user.username = "苏大强" user.password = "123" db.session.add(user) db.session.commit() if __name__ == '__main__': app.run()

settings.py:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
DIALECT = 'mysql' DRIVER = 'pymysql' USERNAME = 'root' PASSWORD = 'root' HOST = 'localhost' PORT = '3306' DATABASE = 'py1901' SQLALCHEMY_DATABASE_URI = '{}+{}://{}:{}@{}:{}/{}?charset=utf8'.format( DIALECT, DRIVER, USERNAME, PASSWORD, HOST, PORT, DATABASE ) SQLALCHEMY_COMMIT_ON_TEARDOWN = True SQLALCHEMY_TRACK_MODIFICATIONS = True SQLALCHEMY_POOL_SIZE = 10 SQLALCHEMY_MAX_OVERFLOW = 5

welcome.html:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=7" /> <title>江苏省卫生监督业务系统</title> <link href="/static/css/main.css" rel="stylesheet" type="text/css" media="all" /> <script src="/static/js/jquery-1.4.2.min.js" type="text/javascript"></script> </head> <body class="welcome"> </body> </html>

index.html:

复制代码
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
32
33
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=7" /> <title>点餐系统</title> <style> html,body { overflow-x:hidden;} </style> <link href="/static/css/main.css" rel="stylesheet" type="text/css" media="all" /> <script src="/static/js/jquery-1.4.2.min.js" type="text/javascript"></script> <script src="/static/js/jquery.onlyforindex.js" type="text/javascript"></script> </head> <body> <div id="header-wrap"> <iframe allowtransparency="true" frameborder="0" id="header-box" scrolling="no" src="inc-header"></iframe> </div> <div id="main-wrap"> <div id="main-nav"> <iframe frameborder="0" id="siderbar-box" scrolling="no" src="inc-nav"></iframe> </div> <div id="main-content"> <table border="0" cellpadding="0" cellspacing="0" id="main-content-box"> <tr> <td class="toggle"></td> <td class="content-wrap"><iframe frameborder="0" id="content-box" src="welcome" scrolling="auto"></iframe></td> </tr> </table> </div> </div> </body> </html>

inc-nav.html:

复制代码
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=7" /> <title>点餐系统</title> <link href="/static/css/main.css" rel="stylesheet" type="text/css" /> <script src="/static/js/jquery-1.4.2.min.js" type="text/javascript"></script> <script src="/static/js/jquery.treeview.js" type="text/javascript"></script> <link href="/static/css/jquery.treeview.css" rel="stylesheet" type="text/css" /> <script language="javascript"> $().ready(function(){ //树状菜单生成 JQuery Treeview $("#browser").treeview({ //animated菜单展开关闭时动画效果 animated : "slow", //collapsed菜单载入时关闭还是展开 collapsed: false //unique同一层次是否只允许展开一个 //unique: true }); //设置树状菜单外框DIV纵向滚动条属性为自动 $("#nav-box").css("overflowY","auto"); //自动添加a标签title为a标签中的内容 for(var i=0; i<$("span.file a").length; i++ ){ $("span.file a").eq(i).attr("title", $("span.file a").eq(i).text()); } }); //链接转入index.html页面ID为content-box的iframe显示 function urlTarget(urls) { $("#content-box",parent.document.body).attr("src",urls); } </script> </head> <body class="inc-nav-body"> <div id="nav-box"> <ul id="browser" class="filetree"> <li><span class="folder">商家管理</span> <ul> <li><span class="file"><a onclick="urlTarget('selectBusinesses');">商家管理</a></span></li> </ul> </li> {#<li><span class="folder">人员管理</span> <ul> <li><span class="file"><a onclick="urlTarget('content/member-list.html');">人员列表</a></span></li> <li><span class="file"><a onclick="urlTarget('content/staff-entrust.html');">人员授权</a></span></li> <li><span class="file"><a onclick="urlTarget('content/staff-entrust2.html');">被授权人确认</a></span></li> <!-- <li><span class="file"><a onclick="urlTarget('content/training-list.html');">培训考核列表</a></span></li> --> <li><span class="file"><a onclick="urlTarget('content/leadership-list.html');">所级领导名录管理</a></span></li> <li><span class="file"><a onclick="urlTarget('content/leadership-tatisticsReport.html');">所级领导名录统计表</a></span></li> <li><span class="file"><a onclick="urlTarget('content/staff-composition.html');">人员构成情况表</a></span></li> <li><span class="file"><a onclick="urlTarget('content/member-supervisor.html');">卫生监督员管理信息汇总</a></span></li> <li><span class="file"><a onclick="urlTarget('content/member-technicist.html');">专业技术人员基本情况表</a></span></li> <li><span class="file"><a onclick="urlTarget('content/member-administrators.html');">行政管理人员基本情况表</a></span></li> </ul> </li> <li><span class="folder">登录号管理</span> <ul> <li><span class="file"><a onclick="urlTarget('content/userid-list.html');">登录号列表</a></span></li> </ul> </li>#} </ul> </div> </body> </html>

inc-header.html:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=7" /> <title>江苏省卫生监督业务系统</title> <link href="/static/css/main.css" rel="stylesheet" type="text/css" media="all" /> <script language="javascript" src="/static/js/jquery-1.4.2.min.js" type="application/javascript"></script> </head> <body> <div id="header"> <div class="logo-title"> <h1>江苏省卫生监督业务系统</h1> </div> <div class="logout user-icon"> 欢迎登录,<span class="user-text">管理员</span> [<span class="signout-text"><a href="javascript:void(0);" onclick="window.opener=null; window.parent.close();" title="退出系统">退出系统</a></span>] </div> </div> </body> </html>

business-view.html:

复制代码
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=7" /> <title>点餐系统</title> <link href="/static/css/main.css" rel="stylesheet" type="text/css" media="all" /> <script src="/static/js/jquery-1.4.2.min.js" type="text/javascript"></script> </head> <body class="content-pages-body"> <div class="content-pages-wrap"> <div class="commonTitle"> <h2>&gt;&gt; <a href="#">商家管理</a> - 商家信息</h2></div> <table border="0" cellspacing="1" cellpadding="0" class="commonTable"> <form id="institutionCreat" name="institutionCreat" action="" method="post"> <tr> <td width="16%" align="right" class="title"><span class="required">*</span>商家编码:</td> <td width="17%" align="left">{{ business.id }}</td> <td width="16%" align="right" class="title"><span class="required">*</span>商家名称:</td> <td width="17%" align="left">{{ business.bname}}</td> <td width="16%" class="title" align="right"><span class="required">*</span>法人:</td> <td width="17%" align="left">{{ business.corporate}}</td> </tr> <tr> <td width="15%" align="right" class="title"><span class="required">*</span>电话:</td> <td width="19%" align="left">{{ business.tel}}</td> <td align="right" class="title">证件类型:</td> <td align="left" colspan="3">{{ business.idtype}}</td> </tr> <tr> <td align="right" class="title">证件号码:</td> <td align="left" colspan="3">{{ business.idnum}}</td> <td align="right" class="title">营业执照号码:</td> <td align="left">{{ business.licensenum}}</td> </tr> <tr> <td align="right" class="title">地址:</td> <td align="left">{{ business.address}}</td> <td align="right" class="title">图片:</td> <td align="left">{{ business.imgs}}</td> </tr> </form> </table> <!--//commonTable--> </div> <!--//content pages wrap--> </body> </html>

business-list.html:

复制代码
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=7" /> <title>点餐系统</title> <link href="/static/css/main.css" rel="stylesheet" type="text/css" media="all" /> <script src="/static/js/jquery-1.4.2.min.js" type="text/javascript"></script> </head> <body class="content-pages-body"> <div class="content-pages-wrap"> <div class="commonTitle"> <h2>&gt;&gt;条件查询</h2> </div> <table width="100%" border="0" cellspacing="0" cellpadding="0" class="commonTableSearch"> <form id="form-search" name="form-search" action="" method="post"> <tr> <th align="left">商家编号:</th> <td align="left"><input name="textfield6" type="text" class="inputTextNormal" id="textfield6" /></td> <td align="left"><div align="left">商家名称:</div></td> <td align="left"><input name="textfield6" type="text" class="inputTextNormal" id="textfield6" /></td> <td align="left">法人:</td> <td align="left"><input name="textfield62" type="text" class="inputTextNormal" id="textfield62" /></td> <td align="right">&nbsp;</td><td align="right"><button>检索</button></td> </tr> </form> </table> <!--//commonTableSearch--> <div class="btnBar"> <ul class="clearfix"> <li><a href="toAddBusiness" title="商家信息录入" class="btnNormal">新增</a></li> </ul> </div> <table border="0" cellspacing="1" cellpadding="0" class="commonTable"> <tr> <th >商家名称</th> <th>法人</th> <th >电话</th> <th>证件类型</th> <th >证件号码</th> <th >营业执照号码</th> <th >地址</th> <th class="editColM">操作</th> </tr> {% for b in blist %} <tr> <td align="center">{{ b.bname }}</td> <td align="left">{{ b.corporate }}</td> <td align="center">{{ b.tel }}</td> <td align="left"> {{ b.idtype }}</td> <td align="center">{{ b.idnum }}</td> <td align="center">{{ b.licensenum }}</td> <td align="center">{{ b.address }}</td> <td align="center"> <a href="showBusiness/{{ b.id }}" class="btnIconView" title="查看详情"></a> <a href="toUpdateBusiness/{{ b.id }}" class="btnIconEdit" title="更新"></a> <a href="deleteBusiness/{{ b.id }}" onclick="if(!confirm('确定删除吗?')) {return false}" class="btnIconDel" title="删除"></a> </td> </tr> {% endfor %} </table> <!--//commonTable--> <div id="pagelist"> <ul class="clearfix"> <li><a href="#">首页</a></li> <li><a href="#">上页</a></li> <li><a href="#">1</a></li> <li><a href="#">2</a></li> <li class="current">3</li> <li><a href="#">4</a></li> <li><a href="#">5</a></li> <li><a href="#">下页</a></li> <li><a href="#">尾页</a></li> <li class="pageinfo">第3页</li> <li class="pageinfo">共8页</li> </ul> </div> </div> <!--//content pages wrap--> </body> </html>

business-edit.html:

复制代码
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=7" /> <title>点餐系统</title> <link href="/static/css/main.css" rel="stylesheet" type="text/css" media="all" /> <script src="/static/js/jquery-1.4.2.min.js" type="text/javascript"></script> <script> function submitForm() { $('#jvForm').submit(); } </script> </head> <body class="content-pages-body"> <div class="content-pages-wrap"> <div class="commonTitle"><h2>&gt;&gt; <a href="#">商家管理</a> - 商家信息修改</h2></div> <table border="0" cellspacing="1" cellpadding="0" class="commonTable"> <form id="jvForm" name="institutionCreat" action="/updateBusiness" method="post"> <tr> <td align="right"><span class="required">*</span>营业执照编号:</td> <td align="left"><input name="licensenum" type="text" class="inputTextMiddle" id="textfield" value="{{ business.licensenum }}"/></td> <td align="right"><span class="required">*</span>商家名称:</td> <td align="left" colspan="3"><input name="bname" type="text" class="inputTextMiddle" id="textfield" value="{{ business.bname }}"/></td> </tr> <tr> <td align="right"><span class="required">*</span>法人:</td> <td align="left"><input name="corporate" type="text" class="inputTextMiddle" id="textfield2" value="{{ business.corporate }}"/></td> <td align="right"><span class="required">*</span>证件类型:</td> <td align="left" colspan="4"> <input type="radio" name="idtype" id="radio5" value="身份证" {% if business.idtype=='身份证' %}checked{% endif %}/>身份证 <input type="radio" name="idtype" id="radio6" value="军官证" {% if business.idtype=='军官证' %}checked{% endif %}/>军官证 <input type="radio" name="idtype" id="radio7" value="学生证" {% if business.idtype=='学生证' %}checked{% endif %}/>学生证 </td> </tr> <tr> <td align="right">证件号码:</td> <td colspan="3" align="left"><input name="idnum" type="text" class="inputTextLong" id="textfield5" value="{{ business.idnum }}"/></td> <td align="right">电话:</td> <td align="left"><input name="tel" type="text" class="inputTextNormal" id="textfield4" value="{{ business.tel }}"/></td> </tr> <tr> <td align="right"><span class="required">*</span>地址:</td> <td align="left"><input name="address" type="text" class="inputTextNormal" id="textfield6" value="{{ business.address }}" /></td> <td align="right">附件:</td> <td align="left"><input name="files" type="file" /></td> </tr> <input type="hidden" name="id" value="{{ business.id }}"/> <input type="hidden" name="state" value="{{ business.state }}"/> </form> </table> <!--//commonTable--> <div id="formPageButton"> <ul> <li><a href="javascript:submitForm()" title="保存" class="btnShort">保存</a></li> <li><a href="javascript:window.history.go(-1)" title="返回" class="btnShort">返回</a></li> </ul> </div> <!--//commonToolBar--> </div> <!--//content pages wrap--> </body> </html>

business-create.html:

复制代码
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=7" /> <title>点餐系统</title> <link href="/static/css/main.css" rel="stylesheet" type="text/css" media="all" /> <script src="/static/js/jquery-1.4.2.min.js" type="text/javascript"></script> <script> function submitForm() { $('#jvForm').submit(); } </script> </head> <body class="content-pages-body"> <div class="content-pages-wrap"> <div class="commonTitle"><h2>&gt;&gt; <a href="#">商家管理</a> - 商家信息录入</h2></div> <table border="0" cellspacing="1" cellpadding="0" class="commonTable"> <form id="jvForm" name="institutionCreat" action="addBusiness" method="post"> <tr> <td align="right"><span class="required">*</span>营业执照编号:</td> <td align="left"><input name="licensenum" type="text" class="inputTextMiddle" id="textfield" /></td> <td align="right"><span class="required">*</span>商家名称:</td> <td align="left" colspan="3"><input name="bname" type="text" class="inputTextMiddle" id="textfield" /></td> </tr> <tr> <td align="right"><span class="required">*</span>法人:</td> <td align="left"><input name="corporate" type="text" class="inputTextMiddle" id="textfield2" /></td> <td align="right"><span class="required">*</span>证件类型:</td> <td align="left" colspan="4"> <input type="radio" name="idtype" id="radio5" value="身份证" checked/>身份证 <input type="radio" name="idtype" id="radio6" value="军官证" />军官证 <input type="radio" name="idtype" id="radio7" value="学生证" />学生证 </td> </tr> <tr> <td align="right">证件号码:</td> <td colspan="3" align="left"><input name="idnum" type="text" class="inputTextLong" id="textfield5" /></td> <td align="right">电话:</td> <td align="left"><input name="tel" type="text" class="inputTextNormal" id="textfield4" /></td> </tr> <tr> <td align="right"><span class="required">*</span>地址:</td> <td align="left"><input name="address" type="text" class="inputTextNormal" id="textfield6" /></td> <td align="right">附件:</td> <td align="left"><input name="files" type="file" /></td> </tr> </form> </table> <!--//commonTable--> <div id="formPageButton"> <ul> <li><a href="javascript:submitForm()" title="保存" class="btnShort">保存</a></li> <li><a href="javascript:window.history.go(-1)" title="返回" class="btnShort">返回</a></li> </ul> </div> <!--//commonToolBar--> </div> <!--//content pages wrap--> </body> </html>

四、Flask分页

最后

以上就是甜美小刺猬最近收集整理的关于Flask框架的全部内容,更多相关Flask框架内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(57)

评论列表共有 0 条评论

立即
投稿
返回
顶部