Private chat using socket.io and django

I am trying to build the chat part of a system build using django. For that I thought of using this tutorial as a starting point (http://maxburstein.com/blog/realtime-django-using-nodejs-and-socketio/) that uses socket.io and build the user-to-user-chat (private)

My original idea was writing some functions in python that would handle the access to the database and some other functions in javascript that would handle the chat server (something like the chat.js from the example) but I don't know how to integrate those two.

So is there any way I can call a js function from python, get its output and vice-versa?

Or do you recommend something else that's easier or more appropriate to implement?

Thank you very much!