增加显示django消息的时间 [英] Increase displaying time of django messages

查看:110
本文介绍了增加显示django消息的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,每当一个问题被删除时,它会显示一条django消息,该问题被删除。
相关代码是:

In my app, whenever a question is deleted, it shows a django message that question is deleted. Related code is:

from django.contrib import messages

msg= _('Question is deleted')
messages.info(request, msg)

根据需要显示,但是我希望显示消息持续更长时间说至少10秒。或者直到用户点击它。

The message gets displayed as desired, however I want Display message to last longer say for minimum 10 sec. or till the user clicks on it.

在django文档中看到消息到期,但仍然无法弄清楚,我没有任何可以设置为false的消息存储

In django docs saw expiration of messages but still could not figure out, and I have nothing like message storage which i can set to false.

帮助赞赏:)

推荐答案

做是javascript域。以下代码将显示您的消息10秒,或者您可以手动关闭它。在模板中,您可以这样做:

The thing you want to do is javascript domain. Below code will display your messages for 10 sec or you can close it manually. In template you can do like this:

{% for message in messages %}
    <div class="message">
        {{ message }}
        <a href="#" class="del-msg">&times;</a>
    </div>
{% endfor %}

而在javascript中:

And in javascript:

<script>
    $(document).ready(function() {
        // messages timeout for 10 sec 
        setTimeout(function() {
            $('.message').fadeOut('slow');
        }, 10000); // <-- time in milliseconds, 1000 =  1 sec

        // delete message
        $('.del-msg').live('click',function(){
            $('.del-msg').parent().attr('style', 'display:none;');
        })
    });
</script>

这篇关于增加显示django消息的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆