A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

本文主要讲的是路由(动态url)

修改index.py中的代码:


from flask import Flask
app = Flask(__name__)
@app.route('/')
def index():
        return '<h1>welcome to the system</h1>'

@app.route('/menu')
def menu():
return 'this is the menu of the system'

@app.route('/quit')
def quit():
        return 'you will exit the system'
@app.route('/user/<name>')
def info(name):
    return 'hello,%s' % name

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

路由说白了就是导航,根据uri的文件名部分(uri详解请看https://blog.csdn.net/no_loafer/article/details/71486654)访问(执行)不同的函数.
上文代码执行效果如下:
(1)若访问127.0.0.1:5000

(2)若访问127.0.0.1:5000/menu

(3)若访问127.0.0.1:5000/quit

(4)若访问127.0.0.1:5000/user/蓝月

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马