Flask 路由

路由

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

猜你喜欢

转载自www.cnblogs.com/py-web/p/12009316.html
今日推荐