Send Notifications in real time using Python Engineio

Now i have my below views to read and update notifications when recieved by the user, and i am basically using ajax to update them.

but then learnd about python Engineio, now how will i able to implement this on my django vews and website as to send and recieve notifications in real time.

my views

def show_notifications(request, username):

    if is_ajax(request=request):

        if request.user.is_authenticated:
        
            user = User.objects.get(username=username)


            unread_notifications = list(Notification.objects.select_related('received_by').filter(received_by=user, read = False).values_list('message', flat=True).order_by("-created_at"))

            read_notifications = list(Notification.objects.select_related('received_by').filter(received_by=user, read = True).values_list('message', flat=True).order_by("-created_at"))


            return JsonResponse({"unread_notifications": unread_notifications,
                                 "read_notifications": read_notifications})




def update_notifications(request, username):

    if is_ajax(request=request):

        if request.user.is_authenticated:

            user = User.objects.get(username=username)
            notifications = Notification.objects.select_related('received_by').filter(received_by=user, read=False).update(read=True)
                
            return JsonResponse({'status': 'Notifications updated'})

You don’t. Django is fundamentally designed around the “request / response” cycle.

Providing asynchronous communications to the browser is outside the realm of Django itself. That’s why the Django Channels project exists.

You can run an EngineIO server in parallel to your Django environment, allowing it to handle your websocket connections, but I’m not sure what the benefits would be over Channels. (Likewise, you could run ws (node.js) or any other websocket server to do the same.)