Python call from javascript

Possible duplicate:
Python call from JavaScript

I have test.py and test.js

I want to run my test.py by opening test.js I do not know how to create an api, because it is not a web application, but only 2 files that are sitting on my Linux mint desktop.

I do not want to use npapi because it is a simple task, I do not want to use pajamas because it is too difficult to set up a desktop for pajamas, and how to do it?

note that I can use php, ajax, jquery instead of javascript if this can be done with these languages. I can also use C ++ or C instead of python. I just want to know an easy way to do this.

I know this can be done if I use java instead of python, but I want to know if I can do this using python, C or C ++.

+6
source share
1 answer

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) { //do stuff with the 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.

+1
source

Source: https://habr.com/ru/post/911738/


All Articles