Timeline for how to call python command from html page?
Current License: CC BY-SA 3.0
10 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| May 12, 2017 at 10:58 | history | edited | Dalen | CC BY-SA 3.0 |
There was a mismatch between comments and the answer code. I noticed it just now.
|
| Jul 29, 2015 at 15:49 | comment | added | Dalen | Then be good and post it here for all to see it too. So that people can decide what to use. | |
| Jul 29, 2015 at 13:57 | vote | accept | Community Bot | ||
| Jul 28, 2015 at 12:00 | comment | added | Dalen | Your argument to Python script doesn't make too much sense with dash at the beginning (-s=...) in this context. In your main.py it'll make more sense to use cgi module (as I did) instead of picking arguments out of sys.argv and parsing them manually. cgitb module will enable you to see traceback as output to your client. You don't have to use it. To pass what you want from the input box to Python, in my callpy() you can scoop the data out of the search box before '$.get(...)' and construct the assoc array argdict as you need. Then you can remove argdict as callpy() argument. | |
| Jul 28, 2015 at 11:58 | comment | added | Dalen | If you have main.py finished, you have to add an execution line at the beginning (if on Unix), add the line 'print "Content-Type: text/html\n', print all output of your script to stdout, make the script executable, put it in right directory, enable CGI in your web server for that directory and you have CGI script finished. | |
| Jul 28, 2015 at 11:30 | comment | added | Dalen | You may copy-paste my client-side javascript code in your HTML, add what you need instead of 'document.write(data)', and call callpy() function where you need it. You can also modify my CGI script to do the processing you need and enable CGI in your web server to execute it. Other than that, my code shows how it is done, not how you should do it. This you will have to work out by yourself as I don't know what is your setup and what do you exactly need. | |
| Jul 28, 2015 at 11:22 | comment | added | Dalen | Server-side Python code have to be executed by a web server. Execution can be performed in any way I mentioned in my answer. The example server-side script I provided is a CGI script. You may use WSGI instead and if you want, you can use django or flask or whatever you want. The important thing is, your script must receive your arguments from the web site, and produce required output. | |
| Jul 28, 2015 at 11:14 | comment | added | Dalen | argdict is associative array that holds arguments for query string which will be passed to your server-side python script. It will be automatically transformed and passed using POST method. I called it argdict because it is defined same as in Python and it has the same purpose. See how I called callpy() function inside an onclick event. | |
| Jul 28, 2015 at 5:58 | comment | added | user3946530 | what is argdict ? and server side i need to add new file or edit in pre existing file ? | |
| Jul 27, 2015 at 14:14 | history | answered | Dalen | CC BY-SA 3.0 |