路由
-
# -*- coding: utf-8 -*-
-
from flask import Flask, url_for
-
-
app = Flask(__name__)
-
-
-
@app.route('/index/<int:year>/<string:mon>', endpoint='index', defaults={"name": 'peach', },
-
strict_slashes=False, redirect_to='https://www.baidu.com/')
-
def index(name, year, mon):
-
"""
-
endpoint: 相当于url_for,默认函数的名, url_for 反向地址,通过视图函数名,或者endpoint 解析出对应的url
-
defaults: 设置默认参数 name
-
strict_slashes: 严格匹配路径
-
redirect_to: 永久重定向,301 不经过视图函数,302重定向是经过视图函数
-
/index/<int:year>/<string:mon>: 动态路由参数,数字可以转字符串, 字符串不能转数字
-
:return:
-
"""
-
return 'index'
-
-
-
app.run(host='0.0.0.0', debug=True)