zoukankan      html  css  js  c++  java
  • flask开发常用的重定向的方式

    方式1:前端重定向,用js代码,延迟2秒后跳转到首页

    <script>
    setTimeout(function () {
    location.href = '/';
    }, 2000);
    </script>

    方式2:前端重定向,用js代码, 注册成功后,延迟1秒钟重新刷新当前页面
    <script>
    setTimeout('location.reload();', 1000);
    </script>


    方式3:前端重定向,用js代码,在页面加载时,就执行该函数
    window.onload = function () {
    fillComment('{{article.articleid}}', '1');

    };

    方式4:后端重定向,接口中跳转,利用响应头部进行重定向
    response = make_response('注销并进行重定向', 302)
    response.headers['Location'] = url_for('index.home') '蓝图.函数'
    或者 
    response.headers['Location'] = '/'

    方式5:后端重定向,​接口中跳转,直接在响应中进行重定向

    @app.route('/redjs')
    def redjs():
    html = '感谢访问,2秒以后将跳转到首页.'
    html += "<script>"
    html += "setTimeout(function() {location.href='/';}, 2000);"
    html += "</script>"
    return html

    方式6:后端重定向
    @app.route('/red')
    def red():
    # return redirect(url_for('index')) # 使用项目中的函数名进行重定向,通过url_for构建重定向地址
    return redirect('/') # 直接指定重定向地址
     



  • 相关阅读:
    semantic-ui 容器与栅格
    semantic-ui 分段
    semantic-ui 分割线
    semantic-ui 图片
    semantic-ui 标题
    semantic-ui 图标
    semantic-ui 按钮
    PHP实现无限级分类
    后端修改配置文件后,前端刷新页面--搭配鉴权
    上线新系统后,统计从旧系统切换到新系统的数据
  • 原文地址:https://www.cnblogs.com/ojbk6943/p/14425615.html
Copyright © 2011-2022 走看看