python编写接口初识一

python编写接口这里用到的是他一个比较轻量级的框架 flask

#!/usr/bin/python
# -*- coding: UTF-8 -*- 

import flask,json
server=flask.Flask(__name__)

@server.route('/index',methods=['get','post'])
def index():
    res={'msg':'这是我开发的第一个借口','msg_code':0}
    return json.dumps(res,ensure_ascii=False)

server.run(port=8888,debug=True,host='localhost')
View Code

然后执行python 文件名.py,

然后在浏览器端输入http://localhost:8888/index

原文地址:https://www.cnblogs.com/ldlx-mars/p/10636691.html