URL_for 在烧瓶蓝图中找不到其他视图

时间:2021-05-08 16:42:37

标签: python flask

我试图将我的flask网站分成多个文件,所以我在一个文件中创建了蓝图,我可以将它导入到main.js中。但是,当我尝试运行它时,它会找到第一个视图(chess_home),但是当我提交时,它找不到下一个视图(chess)。特别是 URL_For 函数不起作用,当我手动将所有信息输入浏览器时,它起作用了。

const configs = {
  win64: { headless: false },
  win32: { headless: false },
  linux: { headless: true },
}

{
  const platforme = "win64";
  const config = configs[platforme] ?? {};
  console.log(config);
}

{
  const platforme = "linux";
  const config = configs[platforme] ?? {};
  console.log(config);
}

{
  const platforme = "aix";
  const config = configs[platforme] ?? {};
  console.log(config);
}
openings_guru = Blueprint('openings_guru', __name__, template_folder='templates')
@openings_guru.route("/chess/", methods=['POST', 'GET'])
def chess_home():
    if request.method == "POST":
        id = request.form["id"]
        color = request.form["color"]
        months = request.form['months']
        sort = request.form['sort']
        return redirect(url_for("chess", id=id, color=color, months=months, sort=sort))
    else:
        return render_template("chess.html")


@openings_guru.route("/chess/<id>/<color>/<months>/<sort>/")
def chess(id, color, months, sort):

1 个答案:

答案 0 :(得分:0)

当我们使用蓝图时,我们也需要改变 url_for 函数,例如:url_for("chess") 变成 url_for("Chess.chess") 其中 Chess 是蓝图的名称。