例如,在重定向之前,我使用
messages.add_message(request, messages.INFO, 'You have successfully updated your listing.')
Run Code Online (Sandbox Code Playgroud)
然后重定向后消息会自动显示,但是消息永远不会消失,我可以知道如何在几秒钟后隐藏它吗?
谢谢!!!
Sat*_*dra 10
您需要编写javascript代码,setTimeout()一段时间后使用window方法隐藏消息。
// suppose the `id` attribute of element is `message_container`.
var message_ele = document.getElementById("message_container");
setTimeout(function(){
message_ele.style.display = "none";
}, 3000);
// Timeout is 3 sec, you can change it
Run Code Online (Sandbox Code Playgroud)
将此代码放在
base.html内部<script>标签的底部,因此每当页面在 3 秒后重新加载时,它都会使您的消息消失。