代码改变世界

flask中redirect用法

2020-09-20 15:02  idea555  阅读(3142)  评论(1)    收藏  举报
1.直接用,可以直接写完整链接,可以写视图函数路径
@index_blu.route('/1111')
def test():
    return redirect('http://www.baidu.com')
  • 1
  • 2
  • 3
@index_blu.route('/3')
def test3():
    return redirect('1111')
  • 1
  • 2
  • 3
2.配合url_for一起用,url_for里面为函数名,如果注册了蓝图,则为蓝图名字.函数名
@index_blu.route('/2')
def test2():
    return redirect(url_for('index.test'))