from flask import Flask
app=Flask(__name__)
@app.route('/user/<int:id>')
def index(id):
if id == 1:
return 'wangyi1'
if id == 2:
return 'wangyi2'
if id == 3:
return 'wangyi3'
return "aaaa"
#参考链接:https://codingdict.com/article/4867
@app.route('/hello/<name>')
def hello_name(name):
return 'Hello %s!' % name
# 传递一个字符串 参考链接: https://blog.csdn.net/qq_33962481/article/details/113760828
@app.route('/user/<username>')
def show_user_profile(username):
# 定义一个字典
city = {'a': '北京', 'b': '上海', 'c': '广东'}
# 返回一个字典的value
return city.get(username)
if __name__ == '__main__':
app.run(host="0.0.0.0", port=5000, debug=True)
'''
http://10.1.71.3:5000/user/a
http://10.1.71.3:5000/hello/<name>
'''
|