Python - 通过python 快速提供接口服务

Python - 通过python 快速提供接口服务


1、安装 flask 模块

2、编写代码

from flask import Flask
import time

app = Flask(__name__)


@app.route('/')
def index():
    return 'hello world';


@app.route('/now')
def now():
    return time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))


if __name__ == '__main__':
    app.run(host='localhost', port=80, debug=True)

3、启动服务

pydev debugger: process 2024 is connecting
Connected to pydev debugger (build 201.7846.77)
 * Serving Flask app "api" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: on
 * Restarting with stat
pydev debugger: process 1012 is connecting
 * Debugger is active!
 * Debugger PIN: 227-495-718
 * Running on http://localhost:80/ (Press CTRL+C to quit)

4、访问服务

在这里插入图片描述

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_15071263/article/details/106989876