a little more help with python server-side scripting

Paul Boddie paul at boddie.org.uk
Fri Feb 24 15:14:24 EST 2006


John Salerno wrote:
>
> Well, I appreciate the help. I'm trying to figure it out, but it seems
> like with each new post, there is some new technology being mentioned or
> new method to do what I'm trying to do.

Let's just consolidate what we've learned here. Your provider says that
you can serve up two different things; the first one being...

 bits of Python code that are embedded within an HTML file

... (this being from a message you quoted), although they don't really
make themselves totally clear, because they then say...

 that after mapping .html will no
 longer be call as normal html file to be loaded on the browser as the
 IIS server now will parse .html with the Python executable engine.
 Your user will need to embed the Python coding into each of the .html
 file in order for it to be load properly on the browser.

...which sounds like ASP to me, noting that the "Python executable
engine" is probably the Active Scripting engine which can work with
Python. So let's call that the "ASP with Python" route.

Now, the other thing they said you could serve up are Python scripts:

 Save your python script as .py file on the wwwroot and
 you may call the scripts using http://www.yourdomain.com/yourfile.py

What these scripts have to do when they run is to output some text
which consists of some headers and the text of a Web page that will
appear in your browser (and you can test them yourself before you
upload them by seeing if they output the expected stuff when you run
them). Let's call this the "CGI with Python" route.

> I guess I'm not well-versed
> enough in Python to even attempt this kind of thing yet. I didn't
> realize it would be this complicated. I guess I hoped it would be as
> easy as including some PHP code and letting the server detect the .php
> extension and handle it all. I'm going to try to solidify the basics
> first, then move on to web programming a little later.

Well, guessing at your configuration from what the support people have
said, it may be simpler to just test things with the "CGI with Python"
option first. So, if you take a CGI program such as one from this
page...

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52220

...like this one...

#!/usr/bin/python
import cgi
cgi.test()

...save it as yourfile.py, upload it as instructed above, and then
visit your site (also as instructed above), you should see some test
output from Python. (Again, you can check the output by running
yourfile.py locally and seeing that it prints out some HTML to the
screen.)

If you want to do the PHP-style thing - the "ASP with Python" option -
then you probably need to make a Web page, similar to that described
here...

http://support.microsoft.com/default.aspx?scid=kb%3Ben-us%3B276494

...save it as yourfile.html (given what they said in their response to
you, although most people thought it should be yourfile.asp - why not
try both?!), upload it, and then visit your site (as instructed above,
but remembering that you're looking for a file called yourfile.html or
yourfile.asp instead of yourfile.py).

If the yourfile.html thing doesn't work but the yourfile.asp does, then
forget about what they said about HTML files and .html and remapping
things: just call your "ASP with Python" files names with .asp on the
end.

To sum up:

 1. Copy the three line "CGI with Python" example, save it as
    yourfile.py, upload it, test it. If it works, celebrate and move
    on to step 2. If it doesn't, move on to step 2 anyway. ;-)

 2. Copy the Web page example from the Microsoft link, save it
    as yourfile.asp and also as yourfile.html, upload them, test
    them. If one of them works, celebrate and note down whether
    you should be using .asp or .html on the end of your filenames.
    If both of them work, celebrate more vigorously! If neither work,
    try and tell us what went wrong.

Good luck!

Paul




More information about the Python-list mailing list