Flask flash 未出现在部署中

Flask flash not appearing on deployment

@app.route("/communicate", methods = ["POST"])
def communicate():
  data = request.get_json()
  for i in data:
    flash(i)
    
  print(data)
  return "Hello"

我有这个 /communicate link 从事件侦听器

获取 json 数据
if (messages.length > 0) {
    e.preventDefault()
    let data = JSON.stringify(messages)
    
    fetch(`${window.origin}/communicate`, {
    method: "POST",
    credentials: "include",
    body: JSON.stringify(messages),
    cache: "no-cache",
    headers: new Headers({
      "content-type": "application/json"
    })
  })
    location.reload()
  }

当我在我的本地测试完全相同的代码时,for 循环内的闪存正在工作。但是,当我将它部署在 heroku 和 pythonanywhere 上时,它停止工作了。

注意:部署时的 /communicate 路由仍然可以很好地从 js 获取数据,只是数据的每个内容都在闪烁。

我尝试了这些方法:

旁注:我使用 location.reload() 刷新页面并 load/update 闪烁的消息。

谢谢~

我看到使用 flash() 之类的东西只会比使用普通 javascript 和使用空的小标签

给我带来更多伤害
const name = document.getElementById('username')
const password = document.getElementById('password')
const form = document.getElementById('mainform')
const second_password = document.getElementById("secure_pass")


const password_error = document.getElementById("password-error")
const second_error = document.getElementById("second-error")
const name_error = document.getElementById("name-error")

form.addEventListener('submit', (e) => {
  let messages = []
  if (name.value === '' || name.value == null) {
    messages.push('Filler')
    name_error.innerText = "Name is required."
  }
  else{
    name_error.innerText = ""
  }

  
  
  
  
  if (password.value != second_password.value || second_password.value != password.value){
    
    messages.push("Filler")
    second_error.innerText = "Password doesn't match"
  }
  else{
    second_error.innerText = ""
  }
  

  if (password.value.length >= 20) {
    messages.push('Filler')
    password_error.innerText = "Password should be less than 20 characters"
  }
  else if (password.value.length <= 8){
    messages.push('Filler')
    password_error.innerText = "Password should be atleast 8 characters"
  }
  else{
    password_error.innerText = ""
  }

  if (password.value === 'password') {
    messages.push('Password cannot be password \n')
  }

  if (messages.length > 0) {
    e.preventDefault()    
  }
 
})

P.s不要介意“填充”我只是添加一个计数器来防止提交。

let count = 0 
count += 1 

更简单