August 27th, 2004, 05:36 PM
Python on the web
While PHP is extremely easy to use, I find Python hard to use for rather simple tasks. I need helping using a special form of a URL. For example, say I want to use the url http://www.mydomain.com/serve?biography...how could I do that. In PHP, you could grab the query string and put in a variable and then redirect. How can I do all this with Python? My web server only has Python 1.5.2, so I'm sure that must limit me in some ways.
To sum things up:
-Includes. What is the python equivalent to include(). Is it just import whatever ?
-Redirection. How can I redirect a user automatically to another page.
-URL manipulation. How can I retrieve the query string using Python?
August 28th, 2004, 03:17 AM
Well it depends on how you mean include, but in general all you would do to include some HTML is read the file using the file() class and print the results.
If you did want to "include" another Python file then yes, you would just import it.
Redirecting in Python is the same as with all CGI so all you need to do is print a Location header before any other content.
I would sugest that you should read some of the articles on Python and CGI in devsheds Python section:
print 'Location:', URL
Hope this helps.
August 28th, 2004, 01:26 PM
or you can use something like Spyce [spyce.sourceforge.net] which allows you to use Python in the same way as PHP. You can run it as CGI, on mod_python or FastCGI to get a big speed boost. The drawback is you have a 0.1% chance that your host has spyce installed and you'd probably need to convince them to install it, or you can find a host that has spyce installed.
August 28th, 2004, 02:39 PM
Trust me...the guys who host my site are morons. I keep insisting they upgrade to the latest version on Python and as a reply I get a generic response "we have Python 1.5."
August 28th, 2004, 07:55 PM
Hahaha, ok id have to agree there thats pretty moronic. If you can get it though, i would get the latest version mod_python with PSP (included) which is basically Python in the style of ASP/PHP/JSP... you get the idea .
It's still pretty young but ive heard some good things so its worth considering.
On the plus side they cant just turn around and say "we have mod_python x.xx". Speaking of which, i dont think its a good idea for them to still have Python 1.52, and since it would like all of 30 min to install