OS X 10.7.5, Python 2.7, Firefox 28.0
I have an HTML form that captures four arguments.
I have a Python file that takes four command line arguments.
What I want is when I hit the 'Submit' button on the form, to invoke the Python file with the four arguments just as if I had done it on the command line:
vmsmith$ ./file.py arg1 arg2 arg3 arg4
I naively tried referencing the Python file in <form ... action="./file.py">, but I got a Firefox box asking me if I wanted to open ./file.py in Xcode.
I suspect I have to invoke the ./file.py somewhere in an intermediary CGI script, but I've scoured the web and cannot find any examples or explanations of how to do it.
In context, I'm not running Apache; rather, I'm running a simple Python CGI server I found here: http://pointlessprogramming.wordpress.com/2011/02/13/python-cgi-tutorial-1/. And I've run some simple CGI scrips with the HTML form and verified that the server, the HTML file, and the CGI scripts all work.
Specifically, given an HTML form with four input fields, the following CGI script works:
#!/usr/local/bin/python
import cgi
import cgitb
cgitb.enable()
form = cgi.FieldStorage()
val1 = form.getvalue('arg1')
val2 = form.getvalue('arg2')
val3 = form.getvalue('arg3')
val4 = form.getvalue('arg4')
I can print all four passed values on a web page, but again, the idea is to invoke file.py with them.