Flask
python
from sys import argv
from flask import Flask, jsonify, request
app = Flask(__name__)
@app.route("/")
def hello_world():
return "<p>Hello, World!</p>"
# 定义动态变量 x
@app.route("/xlog/<path:x>")
def xlog(x):
path = request.args.get('path')
return f"{path},{str(x)}"
if __name__ == '__main__':
args = argv[1:]
is_debug = '--debug' in args
app.run(host='0.0.0.0', port=7400, debug=is_debug)route 转换语法
| Syntax | Description |
|---|---|
| string | (缺省值) 接受任何不包含斜杠的文本 |
| int | 接受正整数 |
| float | 接受正浮点数 |
| path | 类似 string ,但可以包含斜杠 |
| uuid | 接受 UUID 字符串 |
SHELL 启动
shell
# 作为一个捷径,如果文件名为 app.py 或者 wsgi.py ,那么您不需要使用 --app
# --debug 当文件内容变化,会自动重启服务
flask --app hello run --debug --port=3000