How do I display notifications from `django-notification`?

别来无恙 提交于 2019-12-03 03:58:52

问题


I've been reading the docs for django-notification, and they seem to cover creating notifications just fine, but not how to display them to users. Is there a good reference for this out there, and my Google-fu has just failed me? If not, can someone give me some pointers here? Thanks.


回答1:


The answer is you have to build it into your own templates. This can be as simple as the following snippet:

<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>

As @googletorp answered, Pinax is the goto place for figuring out how the authors are using django-notification. In particular, there is a notification administration page that can serve as a handy guide.




回答2:


Tale a look at Pinax the source can be found on github. They use notifications a lot for their project site http://code.pinaxproject.com .

Edit:
I just gave it a look. It seems all that Pinax does to make it work is to list it in installed apps before any the other external apps and include it's urls file like you usually would do.



来源:https://stackoverflow.com/questions/1609775/how-do-i-display-notifications-from-django-notification

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!