Flask 动态参数

#coding=utf-8

from flask import Flask

app = Flask(__name__)


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


@app.route('/wyf')
def hello_wyf():
return 'hello,wyf'


@app.route('/user/<username>') #动态传入 访问 http://127.0.0.1:5000/user/wyf
def show_user_name(username):
return 'User %s' % username


@app.route('/post/<int:post_id>') #动态传入 访问 http://127.0.0.1:5000/post/199
def show_post(post_id):
# show the post with the given id, the id is an integer
return 'Post %d' % post_id


@app.route('/projects/') #访问 http://127.0.0.1:5000/projects
def projects():
return 'The project page'


@app.route('/about') #访问 http://127.0.0.1:5000/about
def about():
return 'The about page'


if __name__ == '__main__':
app.run(host='0.0.0.0', debug=True) #host=‘0.0.0.0’ 保证外网能访问
posted @ 2018-07-24 11:44  王亚锋  阅读(984)  评论(0)    收藏  举报