【问题标题】:django-notifications-hq: cannot show notificationsdjango-notifications-hq:无法显示通知
【发布时间】:2019-02-24 06:52:03
【问题描述】:

虽然 'unread_list' API 有效,但我无法让标签 {% live_notify_list list_class="dropdown-menu" %} 工作。

标签定义为:

def live_notify_list(list_class='live_notify_list'):
  html = "<ul class='{list_class}'></ul>".format(list_class=list_class)
  return format_html(html)

如果我错了,请纠正我,但这只会返回一个未排序的列表。我想显示所有通知。根据文档 (documentation),我需要做的就是使用 {% live_notify_list %} 但是,这不会显示任何内容。

我在github使用的库。

【问题讨论】:

  • 这里不是专家,这看起来好多了,我认为你得到的赞成票强调了这一点!

标签: django django-templates bootstrap-4 django-notification


【解决方案1】:

DevKing,希望您已经解决了这个问题。为了提供更多上下文,{% live_notify_list %} 用于获取可用于导航栏下拉列表的通知的实时更新。用户可以单击并获取最新通知的下拉列表(默认值为 5)。如果您想要所有通知的列表,您可以提供指向 {% url 'notifications:unread' %} 的链接。


你需要包含这个

{% load notifications_tags %}
    <script src="{% static 'notifications/notify.js' %}" type="text/javascript"></script>
    {% register_notify_callbacks callbacks='fill_notification_list,fill_notification_badge' %}

然后你可以把它放在你的导航栏中

            <li class="dropdown">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                    Notifications {% live_notify_badge %}
                    <span class="glyphicon glyphicon-user pull-right">

                    </span>
                </a>
                <ul class="dropdown-menu" id="notice-link">
                  <a href="{% url 'notifications:unread' %}">
                    {% live_notify_list %}
                  </a>
                </ul>
            </li>

{% live_notify_badge %} 将显示未读通知的数量,而 {% live_notify_list %} 将提供最近通知的列表。上面添加的 js 将每 15 秒拉一次新通知(您可以缩短/延长)。

【讨论】:

    猜你喜欢
    • 2021-08-01
    • 1970-01-01
    • 2015-06-28
    • 2012-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多