4-----flask快速入门

达所

Flask官网  https://dormousehole.readthedocs.io/en/latest/patterns/index.html#patterns

from flask import Flask,url_for
import json


app = Flask(__name__)
app.debug= True

@app.route('/')
def hello_world():
    return 'Hello World!'

@app.route('/user/<username>')
def show_user_proeile(username):
    return 'User %s' %username

@app.route('/post/<int:post_id>')
def show_post(post_id):
    return 'Post %s' %post_id

@app.route('/hello/<name>/')
def hello(name=None):
    data = {'a':name}
    return json.dumps(data)


if __name__ == '__main__':
    app.run()

 

posted @ 2020-04-03 10:47  王竹笙  阅读(130)  评论(0编辑  收藏  举报