【问题标题】:Django 2.0 Notifications: How to overwrite the default list.html page for django-notificationsDjango 2.0 通知:如何覆盖 django-notifications 的默认 list.html 页面
【发布时间】:2018-08-22 03:16:24
【问题描述】:
【问题讨论】:
标签:
django
django-notification
【解决方案1】:
您无法创建自己的应用程序notifications,因为您已经安装了一个名为notifications 的应用程序。这是你下载/安装并添加到your_project/settings.pyINSTALLED_APPS下的应用
要查看默认列表,您可以python manage.py runserver,然后导航到localhost:8000/notifications/' to see the defaultlist.html`。
我建议从那里创建您自己的列表。查看文档here,您会发现所有 QuerySet 方法。您可以基于这些查询构建视图。例如your-app/views.py:
...
# Get all unread notifications for current user.
def unread_notifications(request):
context = {
'notifications': request.user.notifications.unread()
}
return render(request, 'your-app/unread_notifications.html', context)
还有你的your-app/unread_notifications.html(假设是引导程序):
<ul class="notifications">
{% for notice in notifications %}
<div class="alert alert-block alert-{{ notice.level }}">
<a class="close pull-right" href="{% url 'notifications:mark_as_read' notice.slug %}">
<i class="icon-close"></i>
</a>
<h4>
<i class="icon-mail{% if notice.unread %}-alt{% endif %}"></i>
{{ notice.actor }}
{{ notice.verb }}
{% if notice.target %}
of {{ notice.target }}
{% endif %}
</h4>
<p>{{ notice.timesince }} ago</p>
<p>{{ notice.description|linebreaksbr }}</p>
<div class="notice-actions">
{% for action in notice.data.actions %}
<a class="btn" href="{{ action.href }}">{{ action.title }}</a>
{% endfor %}
</div>
</div>
{% endfor %}
</ul>