------------恢复内容开始------------
@app.route('/')
def index():
return '<h1>Hello world !<h1>'
index()为视图函数
----------------------------------------------------------------------------------------
定义可变动态路由
@app.route('/usr/<name>')
def usr(name):
return '<h1>Hello,{}!<h1>'.format(name)
-------------------------------
动态路由限定参数类型
@app.route('/student/<类型:id>/')
def student(id):
print(type(id));
print(id);
如果是path类型:可以接受‘/’字符
如果是string类型:不可以接受'/'字符
如果是int类型,只能接受int类型
如果是float类型,只能接受float类型
如果是uuid类型,只能接受uuid类型
枚举any类型
@app.route('/any/<any(a,b,c):an>/')
def any(an):
print(an)
return 'Any'
------------------------------------------------------------------------
uuid值获取
@app.run('/getuuid/')
def get_uuid():
return str(uuid.uuid4())
-------------------------------------------------------------------------------
一个完整应用
from flask import Flask
app=Flask(_name_)
@app.route('/')
def index():
return '<h1>Hello world!</h1>'
-----------------------------------------------------------------------------------------------
app.run的参数:
app.run(debug=True, port=8080, host='127.0.0.1')
------------------------------------------------------------------------------------------------
------------恢复内容结束------------
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。