1

There are some data which would be sent frequently from a django server to the angularjs, this is a data which would be modified frequently and the modification would be updated at the front end when the changes are made at the backend At the point where the data is made available I have inserted

views.py

send_event('test', 'message', {'text': dataModifiedFrequently})

asgi.py

application = ProtocolTypeRouter({
    'http': URLRouter([
        url(r'^event_url/', AuthMiddlewareStack(
            URLRouter(django_eventstream.routing.urlpatterns)
           ), { 'channels': ['test'] }),
        url(r'', get_asgi_application()),
]),

})

angular.js

$scope.EventSourceScope = function(){
    if (typeof(EventSource) !== "undefined") {
        var source = new EventSource('event_url');
        source.onmessage = function (event) {
            $scope.openListingsReport = event.data;
            $scope.$apply();
            console.log($scope.openListingsReport);
                        };
        }   
        else {
            // Sorry! No server-sent events support..
            alert('SSE not supported by browser.');
        }
    }

I used the Django EventStream package and followed the example I do not seem to see any result in the angularjs. but in my browser it gave me the error

EventSource's response has a MIME type ("text/html") that is not "text/event-stream". Aborting the connection.

I followed the example in https://github.com/fanout/django-eventstream.

Please how can I get django to send data to angularjs as it occurs

S Mev
  • 327
  • 3
  • 17
  • When opening the web dev console, do you see the output from your eventstream when using the example with js code ([link](https://github.com/fanout/django-eventstream#receiving-in-the-browser))? – xtlc Mar 15 '22 at 11:17
  • @xtlc Yes i do, I seem to have gotten what is going on. The send_event does not rspond to any other reqest while carrying out the send event – S Mev Mar 31 '22 at 00:42

0 Answers0