flask页面跳转

1) 页面跳转

from flask import Flask,render_template,redirect,url_for

import config

app = Flask(__name__)
app.config.from_object(config)

@app.route("/index")
def hell():
    return 'hi'

@app.route("/name/<id>")
def hi(id):
    if id =="1":
        return render_template("name.html",id=id)
    else:
        return redirect(url_for("hell")) #或 redirect("/index")


if __name__=="__main__":
    app.run()

2)css加载

<linke  href="{{url_for("static",filename="css/index.csss")}}">

3)如果前端使用ajax请求,那么需要使用window.location.href = url;
参考地址:

https://segmentfault.com/q/1010000004983204
$.ajax( {
    type:"post",
    url:"http://www.aaa.com/",
    dataType:"json",
    contentType: "application/json; charset=utf-8",
    data:JSON.stringify({"user_id":1, "user_name":"杨老师"}),
    success:function(msg){
        window.location.href = msg.url;
            }
        })
    })
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值