zoukankan      html  css  js  c++  java
  • Flask框架学习笔记(API接口管理平台 V2.0)

    博主今天把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

  • 相关阅读:
    项目知识
    设计师如何为 Android 应用标注尺寸
    Android开发注意事项
    线程的同步和异步
    复习:IPC机制
    简单的Mvp设计
    泛型
    RxBus的使用
    LinearLayout遇到的问题——利用LinearLayout做横向滑动冲突
    Google搜索技巧、使用Google的其它专业搜索
  • 原文地址:https://www.cnblogs.com/cllovewxq/p/6104380.html
Copyright © 2011-2022 走看看