All you need is to make an ajax request to your pythoncode. You can do this with jquery http://api.jquery.com/jQuery.ajax/, or use just javascript
$.ajax({
type: "POST",
url: "~/pythoncode.py",
data: { param: text}
}).done(function( o ) {
// do something
});
You need to install js2py or requests-html packages to run the JavaScript program from Python
//example :
//javaScript function : squareofNum()
code in python :
import js2py
squareofNum = "function f(x) {return x*x;}"
result = js2py.eval_js(squareofNum)
print(result(5))
>>output : 25