Django 2.0 通知:如何覆盖 django 通知的默认列表.html页面



所以,我最近导入了Django通知,并成功添加了一两个通知。现在我想看一下列表页面。在我的 url 中,我添加了通知终结点path('notifications/', include("notifications.urls")),,当我转到 url 时,我得到与文档匹配的输出:

现在,我该如何更改通知 URL。我试图创建一个用于通知的应用程序python manage.py startapp notifications,但它说已经存在一个。我觉得我错过了一些简单的东西,但我无法指出它。

notifications

,您无法创建自己的应用程序,因为您已经安装了一个名为notifications的应用程序。 这是您下载/安装并添加到your_project/settings.py

下的应用程序INSTALLED_APPS

要查看默认列表,可以python manage.py runserver,然后导航到localhost:8000/notifications/' to see the default列表.html'。

从那里,我建议创建自己的列表。 查看此处的文档,您将找到所有 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>

最新更新