using python with HTML and parameters
John J. Lee
jjl at pobox.com
Wed Jun 30 16:06:52 EDT 2004
"David Stockwell" <winexpert at hotmail.com> writes:
> In java/jsp I can pass parameters to my python script on a webpage by
> doing something like this:
>
> http://somewhere.org/mypage.jsp?parm1=something&parm2=another
Call me picky <wink>, but that looks like a URL to me, not a piece of
Java code.
> How do I do that with python?
If you mean, "how do I pass parameters to a Python CGI script?", then,
well, exactly the same way as to any other CGI script. A URL like the
one you give above, or HTTP POST data (or both).
> Also would I need to import a special module so I could grab them off
> the 'line' (I' m not sure what you call it if its a command line, etc
> as its coming via a 'get' or 'post' request via HTTP protocol.
No, that's the web server's job.
However, if you're writing a CGI script that will handle, you may want
to make use of the standard library cgi module. And, if you're doing
anything more than a quick hack of a script, I'd advise dropping the
cgi module and using one of the many web frameworks available for
Python instead (eg. Quixote).
HTH
John
More information about the Python-list
mailing list