Django using functions from a python class from frontend?
<p>I am new to Django, but i managed to create the back-end and front end for my website but in the front end i am connecting to an external socket and getting data on the fly and i implemented a class that has the function <code>add_data2GraphDB(Data)</code> that adds the element to my graph database</p>

<p>How can I call this function from the front end so it is applied in the back-end without disturbing the rendering of the website.</p>

<p>this is the js code on the front-end page</p>

<pre><code>&lt;script&gt;
eventToListenTo = 'tx'
room = 'inv'

var socket = io("https://blockexplorer.com/");
socket.on('connect', function() {
  // Join the room.
  socket.emit('subscribe', room);
})

socket.on(eventToListenTo, function(data) {

***add_data2GraphDB(Data)***;
})
&lt;/script&gt;
</code></pre>

<p>also after getting the Data i am viewing it in to the user with ability to check the details of this data so it should be added to the graph before viewing it</p>

<p>You can start providing an api point to your Django app that will take parameters from the request body (or/and request parameters) and call your function. So create an url like <code>/api/add2grah</code>. And you call it in the front end with a classic async call.</p>

<p>Now if your function takes a long time, you may want to start using a task queue, so than your api function returns immediately but your add2Graph runs in the back. Good and simple solutions are <a href="https://huey.readthedocs.io/en/latest/django.html" rel="nofollow">Huey</a>, <a href="https://django-q.readthedocs.io" rel="nofollow">Django-q</a> or django-rq (they're simpler than Celery).</p>

<p>Does that answer something ?</p>

javascript python html django neo4j