Flask

中文文档2.3x

Flask 蓝图 Blueprint 

快速开始

        hello.py

from flask import Flask, request

app = Flask(__name__)


@app.route("/")
def hello_world():
    return "

Hello, World!

" @app.route("/api/users") def get_users(): user1 = {'id': 1, 'name': 'zhangsan'} user2 = {'id': 2, 'name': 'lisi'} return [user1, user2] @app.route("/api/user/", methods=['GET']) def get_user(id=None): user = {'id': id, 'name': 'xxxxx'} return user @app.route("/register", methods=['POST']) def user_register(): username = request.json.get("username").strip() # 用户名 password = request.json.get("password").strip() # 密码 if username and password: return "register success" else: return "register fail" ''' if __name__ == '__main__': app.run(port=8000) # app.run() 默认 5000 端口启动 '''

        启动命令

          flask --app hello run   # 默认启动在127.0.0.1:5000

          flask --app hello run --port=9000  # 指定端口启动

你可能感兴趣的:(flask,python,后端)