Write the back-end interface using Python’s flash framework

Time:2021-7-29

After all, it’s time for me, a newcomer to the front end, to write the interface by myself, roll up my sleeves and directly write the code

import pymssql
import time
from flask import Flask, request, jsonify
from flask_cors import CORS

#Database connection
DB = pymssql.connect (host = 'own database address',
                     User = 'user name',
                     Password = 'password',
                     Database = 'database name')
cursor = db.cursor()

#Back end service startup
app = Flask(__name__)
CORS(app, resources=r'/*')

#Interface
@app.route('/myGET', methods=['GET'])
def my_get():
    if request.method == "GET":
    #Business logic
    ···
    
    
#When the business is completed, remember to disconnect the database
if __name__ == "__main__":
    app.run(host='0.0.0.0', port=8888)
    db.close()
    print("good bye")