首页 > 解决方案 > 重定向后如何显示警报指示器?

问题描述

我有一个页面在成功单击提交按钮后将用户重定向到主页。

我想显示这样的指标:

在此处输入图像描述

从提交按钮重定向回主页后,位于主页导航栏下方。

我怎样才能做到这一点?对不起,我是网络开发的新手。

标签: javascripthtmlcssflask

解决方案


我相信您可以在烧瓶中创建一个重定向并设置 cookie 的响应。就像是

from flask import make_response

response = make_response(redirect('/homepage'))
response.set_cookie('show_success_flash', 'true')

return response

然后,在您的 JS 端,您可以读取 cookie,如果它是真的,则显示消息。然后,您可以在关闭 flash 消息时删除 cookie,也可以在 setTimeout 后将其删除。就像是:

// homepage.js


const cookie = import 'js-cookie'

if (cookie.get('show_success_flash') {
  const successFlash = document.getElementById('success_flash_message')

  if (successFlash.style.display === 'none') {
    successFlash.style.display = 'block'
  }
}


推荐阅读