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>I solved the issue by using ajax and also @Ehvince helped me with the concept of the api 
basically in the front-end i used:</p>

<pre><code>$.ajax({
    type:'POST',
    url:'/app/add2Graph/',
    data:{
        tx:data.txid,
        csrfmiddlewaretoken:$('input[name=csrfmiddlewaretoken]').val()
    },
    success:function(result){
    console.log(result)
    }
});
</code></pre>

<p>and in the back-end I added the URL </p>

<pre><code>url(r'^app/add2Graph/$',addTx2graph, name='add2graph'),
</code></pre>

<p>and in the api I added:</p>

<pre><code>def addTx2graph(request):
transactionInfo="Unknown transaction" 
if request.method=='POST':
    tx=request.POST['tx']
    transactionInfo=addTransaction(tx)
return HttpResponse("success")
</code></pre>

javascript python html django neo4j