消息闪现
#消息闪现 @book_bp.route("/book", methods=["GET", "POST"]) def handle_book(): if request.method == "POST": title = request.form.get("title") if title: books.append(title) flash("Add book succussfully.") return redirect(url_for("book.handle_book")) else: flash("Add failed", "error") return render_template("book.html", books=books) #jinja模版中使用 {% for message in get_flashed_messages()%} {{ message }} {% endfor %} {% with error_message = get_flashed_messages(category_filter=["error"]) %} {% for error in error_message %} {{ error }} {% endfor %} {% endwith %}