Python-based API Interface management platform Development (V1.0)

Source: Internet
Author: User
Tags import database

Today Bo Master finally completed the API interface management platform, the final difference is the maintenance of the database,

Bo Master here introduces the design principles of the platform, first based on Python, using Flask web framework +bootstrap front-end framework completed, the first stage to complete the front page display

Second phase to join login exit, background management

Here is the Document Map

Python third-party modules involved: flask, Flask-bootstrap, SQLAlchemy

Layout of the Overall page: page header navigation, API classification on the right, page information

Page information content includes: interface description, request parameters, return parameters, request example, return example

The following is the model.py file that defines the database object

#!/usr/bin/env python#-*-coding:utf-8-*- fromSQLAlchemyImportColumn, Create_engine fromSqlalchemy.ormImportSessionmaker fromSqlalchemy.ext.declarativeImportDeclarative_baseImportJSONImportSYS#Import Database All table field types fromSqlalchemy.dialects.mysqlImportBIGINT, BINARY, BIT, BLOB, BOOLEAN, CHAR, DATE, DATETIME, Decimal, Decimal, DOUBLE, ENUM, FLOAT, INTEGER, Longblob, Longtext, Mediumblob, Mediumint, Mediumtext, NCHAR, NUMERIC, NVARCHAR, REAL, SET, SMALLINT, TEXT, Time, TIM Estamp, Tinyblob, TINYINT, Tinytext, VARBINARY, VARCHAR, year#to create a base class for an object:Base =declarative_base () reload (SYS) sys.setdefaultencoding ("Utf-8")#Defining API Table ObjectsclassApi (Base):#Name of the table:    __tablename__='API'    #Structure of the table:id = Column (INTEGER), primary_key=True) name= Column (VARCHAR (50)) URL=Column (TEXT) method= Column (VARCHAR (10)) Service= Column (VARCHAR (50)) Access_token= Column (VARCHAR (255)) Reqparam=Column (TEXT) Response=Column (TEXT) Requestexam=Column (TEXT) Responseexam=Column (TEXT)#Defining model Table ObjectsclassModel (Base):#Name of the table:    __tablename__='Model'    #Structure of the table:id = Column (VARCHAR), primary_key=True) name= Column (VARCHAR (50)) Ch_name= Column (VARCHAR (50)) from_id= Column (VARCHAR (25))

Here is an attempt to views.py

#!/usr/bin/env python#-*-coding:utf-8-*- fromAppImportapp fromFlaskImportrender_template, Flash, redirect, session, Url_for, request, G fromModelsImportApi, Model fromConfigImportconnect_dbImportJSONImportsysreload (SYS) sys.setdefaultencoding ("Utf-8") @app. Route ("/") @app. Route ("/index")defindex ():returnRender_template ("index.html") @app. Route ("/<id>", methods=["GET","POST"])defmodel (ID): All_name=[] DB=connect_db () conn=db () Table_model= Conn.query (Model). Filter (Model.name = =ID). One () Model_name=table_model.name Model_ch_name=table_model.ch_name Model_all= Conn.query (Model). Filter (model.from_id = =table_model.id). All () forIinchRange (len (model_all)): Name= {"Ch_name": Model_all[i].ch_name,"name": Model_all[i].name} all_name.append (name) conn.close ()returnRender_template ("model.html", Model_name=Model_name, Model_ch_name=Model_ch_name, All_name=all_name) @app. Route ("/desk/<id>")defform (ID): All_names=[] DB=connect_db () conn=db () Table_model= Conn.query (Model). Filter (Model.name = =ID). One () Model_all= Conn.query (Model). Filter (model.from_id = =table_model.from_id). All () forIinchRange (len (model_all)): Name= {"Ch_name": Model_all[i].ch_name,"name": Model_all[i].name} all_names.append (name) model_id= Conn.query (Model). Filter (Model.id = =table_model.from_id). One () Model_ch_name=model_id.ch_name Model_name=model_id.name Table_api= Conn.query (API). Filter (Api.id = =table_model.id). One () name=table_api.name URL=Table_api.url Method=Table_api.method Service=json.loads (table_api.service) Access_token=json.loads (table_api.access_token) Reqparam=json.loads (table_api.reqparam) Response=json.loads (table_api.response) Request_exam=Table_api.requestexam Response_exam=table_api.responseexam conn.close ()returnRender_template ("form.html", the URL=URL, method=method, Name=name, All_names=All_names, Model_name=Model_name, Model_ch_name=Model_ch_name, Service=Service, Access_token=Access_token, Reqparam=Reqparam, Response=response, Request_exam=Request_exam, Response_exam=response_exam)

Bloggers define views based on routing to the Home page, module, and interface

Finally, let's see the effect.

Python-based API Interface management platform Development (V1.0)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.