a little more help with python server-side scripting

Magnus Lycka lycka at carmen.se
Fri Feb 24 03:56:58 EST 2006


John Salerno wrote:
  > Ok, seems like the verdict is that the server doesn't have mod_python
> nor does it detect the .psp extension. It can, however, detect the .py 
> extension. But does this mean I can simply include Python code in my 
> HTML files, and then give my HTML files a .py extension? I don't know 
> how to test this because I don't know how to write inline code yet. Is 
> it something like:

No, you can't do that. From your descriptions, it seems that Python
is set up as a CGI language, just as one would use Perl etc. This
means that if you have an URL ending with x.py, the web server will
do these things when you request this URL from the server:

1. Set up a number of environment variables which are useful for the
    python script it will call. Very important if the URL was invoked
    from an HTML form, which I don't suspect will happen on your site.
2. Invoke Python with your script. Basically it should call
    python.exe -u x.py
3. Read the data that x.py sends to stdout, e.g. print statements
    etc. Provided that this output looks ok, it will send it to the
    browser, otherwise it will typically send ERROR 500 (internal
    server error) instead.

You were given a CGI script already that printed out environment
variables. I got the impression that you tried that out. If you
set the environment variables shown by that CGI script using the
SET command at a Windows command prompt, and then execute your
python script at that command prompt, it has to print something like

----
Content-type: text/html

<html>
blah blah whatever
</html>
----

There is no magic beyond this. Try renaming an HTML file to .py
and invoke Python with that. It will just say SyntaxError! The
change isn't big though! You just need to make the HTML content
into a big string (surround it with """) and print the content-type
line, an empty line and this big string, and you have a start.

You have already been provided with all the information you need.
I think you need to look closely at the information Paul and several
others have given you instead of just asking more questions, and
really start using it. You won't get anywhere otherwise.

The other option is ASP. You have been given information about
that already. Be aware that ASP does not imply VBScript. You can
use Python in ASP as long as that's enabled. It seems to be exactly
what you are asking for, so I don't understand why you seem to reject
it. Don't you like the file name endings?



More information about the Python-list mailing list