#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2001
    Posts
    52
    Rep Power
    13

    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?

    Thanks,
    Ryan
  2. #2
  3. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    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.

    Code:
    print 'Location:', URL
    I would sugest that you should read some of the articles on Python and CGI in devsheds Python section:

    http://www.devshed.com/c/a/Python/Writing-CGI-Programs-in-Python/
    http://www.devshed.com/c/a/Python/Python-on-the-Web/
    http://www.devshed.com/c/a/Python/MySQL-Connectivity-With-Python/

    Hope this helps.

    Mark.
    programming language development: www.netytan.com Hula

  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2002
    Posts
    89
    Rep Power
    13
    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.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2001
    Posts
    52
    Rep Power
    13
    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."
  8. #5
  9. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    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

    Take care

    Mark.
    programming language development: www.netytan.com Hula


IMN logo majestic logo threadwatch logo seochat tools logo