關於Flask中的重定向問題
阿新 • • 發佈:2019-01-04
from flask import Blueprint, request, render_template, make_response, redirect, url_for blue = Blueprint('first', '__name__') # 帶引數的render_template @blue.route('/getfile/<name>/') def getFile(name): red = render_template("hello.html", name=name) resp = make_response(red, 502) print(resp) return resp # 帶引數的render_template @blue.route('/getredic/<name>/') def getredic(name): redic = redirect(url_for('first.getFile', name=name)) return redic
關於hello.html的HTML文件
<h2>{{ name }}好煩!想打聯盟!</h2>
hello.html 存在於template中 也可以直接在示圖函式直接建立 再按Alt+回車鍵 建立
要點一 : 重定向redirect(url_for('路由的名字.需要重定向示圖函式的名字',引數名=引數名))
@blue點的是示圖函式的名字不是路由的名字