Use Django's Messages Framework with Django Rest Framework.
Requirements:
- Python (3.7, 3.8, 3.9)
- Django (2.2, 3.0, 3.1, 3.2)
- Django Rest Framework (3.7-3.12)
Django's message framework is awesome, and now its even better with Django Rest Framework!
The django's messages framework is a very easy and quick way to provide one-time messages for the user. When using django rest framework you loose most of the functionality of it. Using this app you can access your messages though a rest api endpoint.
- Persistent message storage in database
- Automatic cleanup
- DRF endpoint for accessing messages
- Install using:
$ pip install drf-messages
- Configure project
settings.py
:
INSTALLED_APPS = [
# ...
'django.contrib.messages',
'rest_framework',
'drf_messages',
# ...
]
MESSAGE_STORAGE = "drf_messages.storage.DBStorage"
- Configure routes at your project's
urls.py
urlpatterns = [
path('messages/', include('drf_messages.urls')),
# ...
]
- Run migrations using:
$ py manage.py migrate drf_messages
For more details visit the docs for installation: https://drf-messages.readthedocs.io/en/latest/installation/installation.html
You can list all your messages with:
$ curl -X GET "http://localhost/messages/"
Any unread messages will have read_at
as null
.
If you have django-filter
configured, you can also query "http://localhost/messages/?unread=true" to get only unread messages.
In case you have trouble while using this module, you may use the GitHub Disccussion.
For any bug or issue, open a new GitHub Issue.