Skip to main content
https://travis-ci.org/matthiask/django-user-messages.svg?branch=master Documentation Status

django-user-messages adds offline messaging support to Django’s messaging framework. It achieves this by allowing to save messages in the database. The user_messages.api.get_messages utility and the user_messages.context_processors.messages context processor transparently concatenate Django’s messages and our own messages in a single list, therefore existing code works without any changes and without causing database writes. django-user-messages’ functions have to be used explicitly. I consider this a feature, not a bug.

Installation

  • Install django-user-messages using pip into your virtualenv.

  • Add user_messages to INSTALLED_APPS and run migrate.

  • Replace the default messages context processor with user_messages.context_processors.messages. The context processor provides both django.contrib.messages’ and django-user-messages’ messages. Note that Django 2.2’s admin app checks for the presence of the default messages context processor, so you’ll have to silence this check by adding "admin.E404" to the SILENCED_SYSTEM_CHECKS setting.

  • Use user_messages.api as you would use django.contrib.messages except that you pass the user model or ID as first parameter, not the current request.

Usage

Pretty much the same as Django’s messaging framework:

from user_messages import api

api.info(user, 'Hey there')
api.warning(user, 'Stop this')
api.error(user, 'Not nice!')

# Passing the ID is also possible; the user instance does not
# have to be instantiated at all:
api.success(user.id, 'Yay!')

django-user-messages’ messages supports two additional features not available in Django’s messages framework:

  • Messages can be delivered more than once by passing deliver_once=False. These messages have to be acknowledged explicitly. django-user-messages does not contain any code to do this.

  • It is possible to attach additional data by passing a dictionary as meta:

    api.debug(user, 'Oww', meta={
        'url': 'http://example.com',
    })

For convenience, our messages have the same tags and level_tag properties as Django’s messages. Meta properties are also accessible in templates:

{% if messages %}
  <ul class="messages">
  {% for message in messages %}
    <li class="{{ message.tags }}".>
      {% if message.meta.url %}<a href="{{ message.meta.url }}">{% endif %}
      {{ message }}
      {% if message.meta.url %}</a>{% endif %}
    </li>
  {% endfor %}
  </ul>
{% endif %}

django-user-messages’ messages are also evaluated lazily.

Metadata

Release files for django_user_messages 0.6.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django_user_messages 0.6.2
File Size Uploaded
django-user-messages-0.6.2.tar.gz 7.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django_user_messages 0.6.2
File Interpreter ABI Platform
django_user_messages-0.6.2-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 18.6 kB

Release files / django-user-messages-0.6.2.tar.gz

Download URL django-user-messages-0.6.2.tar.gz
Size 7.4 kB
Tags Source
SHA-256 checksum
How to use checksums
2f54081f482af5d63ae90469da3d2befdc93ff9b15d05024f11368d809f16486
BLAKE2b-256 checksum
How to use checksums
04a2b818c3a624b4db98016d5692f6ff2ff2c409f8352e9f2dc99752b3bdf7dc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/3.6.8

Release files / django_user_messages-0.6.2-py2.py3-none-any.whl

Download URL django_user_messages-0.6.2-py2.py3-none-any.whl
Size 11.2 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
0b04f76ada115f3e5f67e598e72d560414bc06fe317ac12f77b2121cb80369ba
BLAKE2b-256 checksum
How to use checksums
afe6d97895fd43843946721048a58e901606c889841178b725889d6f12349986
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/3.6.8

Release history Release notifications | RSS feed

1.1.0

2 release files

1.0.0

2 release files

0.8.0

2 release files

0.7.0

2 release files

This release

0.6.2 This release

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page