django-eventstream
django-eventstream copied to clipboard
get stuck with send_event
Hello, I've been stuck with send_event function.
my backend is generating image frames after processing a video, I want to send these frames directly to frontend. but I tried using this library.
whenever I send a get request to /events/ it displayed
event: stream-open data
after that when I use send_event function with type that I specified in the urlpatterns, but unfortunately nothing happens
path('events/', include(django_eventstream.urls), {'channels': 'test'}),
def get(self, request):
send_event('test', 'message', {"test": "asdsa"})
return HttpResponse()
whenever I hit this view, I received nothing on the frontend. my frontend is react
useEffect(() => {
const eventSource = new EventSource("http://localhost:8000/events/");
eventSource.onopen = (e) => console.log("opened");
eventSource.onmessage = (e) => console.log(e);
}, []);
I notice you're setting a path
entry, which is usually part of urls.py
and used for WSGI setups. However, Django Channels requires setting up ASGI-based routes. See for example: https://github.com/fanout/django-eventstream/blob/master/examples/chat/server/asgi.py#L30
Got it. Now it's working fine.
Thank you very much. This library makes my FYP easier.