本文主要讲的是路由(动态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

Flask 入门(二)

(2)若访问127.0.0.1:5000/menu

Flask 入门(二)

(3)若访问127.0.0.1:5000/quit

Flask 入门(二)

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

Flask 入门(二)



相关文章:

  • 2021-04-05
  • 2021-12-11
  • 2021-04-04
猜你喜欢
  • 2018-05-29
  • 2022-01-05
  • 2021-07-20
  • 2022-12-23
  • 2021-04-25
  • 2019-06-03
  • 2021-08-24
相关资源
相似解决方案