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;
}
})
})