django-eventstream
django-eventstream copied to clipboard
Adding support for Django RestFramework
Related to: #140
Hi, I've just upgraded the plugin to fully support the Django Rest Framework.
Modifications include:
- The old code has been retained, with minor upgrades.
- Adding to
django_eventstream.utils
aget_cors_from_settings
method
- Adding to
- Rearranged the static folder organization.
- Added a viewset for Server-Sent Events (SSE) that is capable of redirecting to the correct renderer with the appropriate response.
- Introduced a renderer for SSE streams. This renderer is equipped to handle SSE streams with the correct response headers and the right content type.
- Implemented a renderer for the SSE browsable API:
- Added
browsable-api-eventstream.html
, a template file that is an edited version of thebase.html
file from the Django Rest Framework. - Added
browsable-api-eventstream.js
, a JavaScript script that provides all the necessary functionality for thebrowsable-api-eventstream.html
template to correctly display the SSE stream, usingreconnecting-eventsource.js
. - Added
browsable-api-eventstream.css
to supply the CSS for thebrowsable-api-eventstream.html
template.
- Added
- Updated DOCs
- Adding possibility to install with or without Django Rest Framework. Check
__init__.py
files. - Adding a fully functional example
chat-restframework
The Browsable API is fully usable, as shown here:

The system will automatically return an SSE Stream when called by a request header that contains Accept: text/event-stream
.