【发布时间】:2010-12-09 05:57:40
【问题描述】:
我一直在阅读django-notification 的文档,它们似乎涵盖了创建通知的内容,但不包括如何向用户显示它们。有没有一个很好的参考,我的谷歌fu刚刚让我失望了?如果没有,有人可以在这里给我一些指示吗?谢谢。
【问题讨论】:
标签: python django django-notification
我一直在阅读django-notification 的文档,它们似乎涵盖了创建通知的内容,但不包括如何向用户显示它们。有没有一个很好的参考,我的谷歌fu刚刚让我失望了?如果没有,有人可以在这里给我一些指示吗?谢谢。
【问题讨论】:
标签: python django django-notification
答案是您必须将其构建到您自己的模板中。这可以像下面的 sn-p 一样简单:
<table>
<caption>{% trans "Notices" %}</caption>
<thead>
<tr>
<th>{% trans "Type" %}</th>
<th>{% trans "Message" %}</th>
<th>{% trans "Date of the Notice" %}</th>
</tr>
</thead>
<tbody>
{% for notice in notices %}
{% if notice.is_unseen %}
<tr class="unseen_notice">
{% else %}
<tr class="notice">
{% endif %}
<td class="notice_type">[{% trans notice.notice_type.display %}]</td>
<td class="notice_message">{{ notice.message|safe }}</td>
<td class="notice_time">{{ notice.added|timesince }} {% trans "ago" %}</td>
</tr>
{% endfor %}
</tbody>
</table>
作为@googletorp answered,Pinax 是了解作者如何使用django-notification 的最佳去处。特别是,有一个通知管理页面,可以作为一个方便的指南。
【讨论】:
notification.context_processors.notification,它是由django-notification 本身提供的。上面的示例是django-notification 定义的notices 视图的模板;那应该是notification/notices.html 模板。请参阅github.com/pinax/django-notification/blob/master/notification/… 了解更多信息。
故事看看Pinax 可以在 github 上找到源代码。他们在项目站点http://code.pinaxproject.com 中经常使用通知。
编辑:
我只是看了一下。似乎 Pinax 所做的所有工作都是在安装的应用程序中列出它,然后再将其列在任何其他外部应用程序中,并像往常一样包含它的 urls 文件。
【讨论】:
django-notification 的模板(我相信 notification/notices.html 就是这样一个例子)。我希望有一个入门风格的教程来解释不同的部分是如何组合在一起的。