Flask内如何跳转至其他页面。

为了能从当前的路由跳转至其他路由,我如下写的:

  @app.route('/',methods=['POST','GET'])
        def index():
            if request.args.get('data',type=int)==1: #判断是否前往
                return redirect(url_for('about'))
            return render_template('index.html')
        @app.route('/about')
            def about():
             :
             :
        return render_template('about.html')

但是没有用,然后我又改成:

 return render_template('about.html')

然后依然没用,页面都不会跳转 (肯定进了if的)
现在很茫然,不知道怎么办 求教

阅读 22.2k
3 个回答

加个点

redirect(url_for(".about"))

大兄弟,你的问题解决了么?我现在碰到和你一样的问题了。

新手上路,请多包涵

如果是跳转其他路由你应该考虑用return redirect(url_for("about"))
render_template是跳转静态资源,直接返回静态资源,而不是跳转路由

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题