当一个是 sending/receiving JSON 时,`flash('Helpful Message')` 的成语是什么?

What is the idiom for `flash('Helpful Message')` when one is sending/receiving JSON?

在我的 Jinja2 HTML 模板文件的 base.html

{% for message in get_flashed_messages() %}
    <div>
        {{ message }}
    </div>
{% endfor %}

这很好用。无论我在哪里

from flask import render_template

@main.route('/', methods=['GET', 'POST'])
def index():
    if is_invalid():
        flash('Invalid')
    return render_template('index.html')

返回文件 index.html 并出现相应的闪烁消息,因为 index.html 派生自 base.html

如果我更新整个页面,情况会稍微复杂一些。仍然派生自 base.html 的文件 details.html 重绘成本太高。当用户触发事件时,服务器接收到 (JSON) API 调用,响应在 JavaScript 中被解释为更新 details.html 的(部分)。

我不想重新发明轮子。当 sending/receiving JSON 时 flash('Helpful Message') 的恰当成语是什么?

你需要在 javascript 而不是神社

通常你会在顶部创建一个“错误”div

<div class="error" id="errorMessage"></div>

然后您将在响应时填充它

fetch(someurl).then(r=>r.json()).then(data=>{
    document.getElementById("errorMessage").innerText = "Helpful message"
})

of coarse 你可以使用 alert("Helpful Message") 或者你可能想使用一些 (javascript) UI 库,它提供了一个简单且更强大的警报消息系统