If you put your test.py file wherever you place your cgi files (I think it is / usr / lib / cgi -bin by default for apache on ubuntu linux), you should be able to run the python file just by contacting to his address.
If you just want to run the python file and not use its output in the browser, you could probably get away with something like:
document.write('<img src="http://localhost/cgi-bin/test.py" />');
if you want to use the output in a browser, you will most likely be best off using jQuery or some other library to make a simple ajax call.
sort of:
jQuery.get('/cgi-bin/test.py', function(data) {
maybe you're just fine.
the second method will require that you also use apache or the equivalent to serve the test.js file from localhost, since jQuery ajax usually requires that the requests go to the same domain the script is running on.
source share