码迷,mamicode.com
首页 > Windows程序 > 详细

Flask框架学习笔记(API接口管理平台 V2.0)

时间:2016-11-26 17:50:35      阅读:1011      评论:0      收藏:0      [点我收藏+]

标签:auto   请求   2.0   list   分享   没有   github   结构   rem   

博主今天把API接口管理平台发布到github了,这次是更新一些功能

技术分享

如支持本地数据库sqlite3、优化了数据结构

技术方面跟之前V1.0相同,只增加生产本地数据;但是为了支持层级的参数,修改了数据结构,下面是新的model.py

 1 #!/usr/bin/env python
 2 # -*- coding: utf-8 -*-
 3 
 4 from app import db
 5 
 6 
 7 class User(db.Model):
 8     user_id = db.Column(db.Integer, primary_key=True, autoincrement=True)
 9     user_name = db.Column(db.String(64))
10     password = db.Column(db.String(64))
11     status = db.Column(db.Integer)
12     level = db.Column(db.Integer)
13 
14 
15 class Model(db.Model):
16     model_id = db.Column(db.Integer, primary_key=True, autoincrement=True)
17     model_name = db.Column(db.String(256))
18     status = db.Column(db.Integer)
19     # 项目分类ID、名称、状态
20 
21 
22 class Interface(db.Model):
23     interface_id = db.Column(db.Integer, primary_key=True, autoincrement=True)
24     model_id = db.Column(db.Integer, db.ForeignKey("model.model_id"))
25     interface_name = db.Column(db.String(64))
26     interface_url = db.Column(db.String(1024))
27     interface_method = db.Column(db.String(64))
28     request_exam = db.Column(db.String(4096))
29     response_exam = db.Column(db.String(4096))
30     status = db.Column(db.Integer)
31     # 接口信息
32     
33 
34 class Parameter(db.Model):
35     parameter_id = db.Column(db.Integer, primary_key=True, autoincrement=True)
36     interface_id = db.Column(db.Integer, db.ForeignKey("interface.interface_id"))
37     parameter_type = db.Column(db.String(64))
38     parameter_group_id = db.Column(db.Integer)
39     parameter_name = db.Column(db.String(64))
40     necessary = db.Column(db.String(64))
41     type = db.Column(db.String(64))
42     default = db.Column(db.String(64))
43     remark = db.Column(db.String(64))
44     level = db.Column(db.String(64))
45     # 参数信息

然后是根据定义好的结构重新定义表单字段 forms.py

 1 #!/usr/bin/env python
 2 # -*- coding: utf-8 -*-
 3 
 4 from flask_wtf import Form
 5 from wtforms import StringField, TextField, PasswordField, FormField, SubmitField, FieldList, IntegerField
 6 from wtforms.validators import Required, DataRequired
 7 
 8 
 9 class LoginForm(Form):
10     username = StringField("登陆名", validators=[Required()])
11     password = PasswordField("密码", validators=[Required()])
12 
13 
14 class ModelForm(Form):
15     model_name = StringField("中文名称", validators=[Required()])
16 
17 
18 class InterfaceForm(Form):
19     interface_name = StringField("接口名称", validators=[Required()])
20     interface_url = StringField("接口地址", validators=[Required()])
21     interface_method = StringField("接口方法", validators=[Required()])
22     request_exam = TextField("请求示例", validators=[Required()])
23     response_exam = TextField("返回示例", validators=[Required()])
24 
25 
26 class ParameterRequestForm(Form):
27     parameter_group_id = StringField("从属", validators=[Required()])
28     parameter_name = StringField("参数名称", validators=[Required()])
29     necessary = StringField("是否必须", validators=[Required()])
30     type = StringField("类型", validators=[Required()])
31     default = StringField("默认值", validators=[Required()])
32     remark = StringField("备注", validators=[Required()])
33     level = StringField("层级", validators=[Required()])
34 
35 
36 class ParameterResponseForm(Form):
37     parameter_group_id = StringField("从属", validators=[Required()])
38     parameter_name = StringField("参数名称", validators=[Required()])
39     necessary = StringField("是否必须", validators=[Required()])
40     type = StringField("类型", validators=[Required()])
41     default = StringField("示例", validators=[Required()])
42     remark = StringField("描述", validators=[Required()])
43     level = StringField("层级", validators=[Required()])
44 
45 
46 class SubmitForm(Form):
47     submit = SubmitField("保存")

关系总结就是 项目分类下有接口、接口中有参数、参数又分为 请求参数;返回参数

还增加了后台管理:

技术分享

github地址:https://github.com/cllovewxq/pythonapi

这边博主没有把用户管理完成、还有使用项目过程中有用户密码的话就用:admin/123456

 

Flask框架学习笔记(API接口管理平台 V2.0)

标签:auto   请求   2.0   list   分享   没有   github   结构   rem   

原文地址:http://www.cnblogs.com/cllovewxq/p/6104380.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!