[mod_python] How do I serve up .html files?

StianSøiland stian at soiland.no
Wed Aug 27 20:38:45 EST 2003


On 2003-08-27 02:12:29, Kirk Bailey wrote:

(this is the non-personal answer about the TECHNICAL things, not
including my previous private answers.. =) )

> Stian, I sugggest you be nice, and not go trolling. He asked a basic 
> question about how to get a html page to access a cgi program; Go back and 
> read the letter he wrote. I was discussing exactly that. One gets a page to 
> access a script with a ssi tag. He did NOT ask how to configure apache, or 
> how mod_python works. He asked how to get a page when requested to acess a 
> cgi program. I was addressing exactly that point, at a basic level. 
> Granted, his letter was a tad off topic, and even a little below the 
> general level of technical skill devlopment this list usually displays, but 
> he asked, I replied, being a generally helpful person.

About the technical issue, CGI was never asked about, mod_python is
normally used INSTEAD of cgi. 

The question was really how to run a python handler for every possible
URL, not to include cgi-output withing HTML.

(in which case I would have solved it anyway by using the mod_python
solution presented in this thread)


A quick note about the SetHandler trick (I use it to get virtual URLs -
what I would like to see is some functionallity from Publisher (argument
parsing, return content-type-magic) - used together with virtual URLs.
Ie allowing /browse/some-switch.domain.com/switchports without actually
having the object "some-switch.domain.com" - the quick solution probably
being some __getattr__-magic) 


Remember that even though you SetHandler to something, 
you'll also need to set DirectoryIndex to some EXISTING FILE. I did this
error as I included all python code in the pythonpath and had no files
in the actual path. I used SetHandler nav.web.devBrowser.dispatcher
in .htaccess for a blank directory.

Now, DirectoryIndex could not simply be index.html, as there were no
file index.html. I created a file "index" in the otherwise blank
directory, set DirectoryIndex to "index", and everything worked.

If the file is removed, the blank directory listing is presented, but
other urls within the directory works.

(the handler receives the request as being to /index, and the file is
never actually read from disk due to SetHandler intercepting)

Now, some gurus might have a suggestion about getting rid of that empty
file. If so, please let me know! =)


Why not have the files inside the directory? Well, we've encountered
*some* problems with developers each making "index.py" (they 
previously programmed PHP!) - within the same namespace (ie.
Subinterpreter). This caused problems like getting some modules from
each of the users public_html directory. Funny!

We've used PythonInterpPerDirectory while developing, but needs to get
rid of that before merging code, as this eats database connections as a
horse. (remember, one connection pr database pr. interpreter pr.
apache.. scales up!)


-- 
Stian Søiland               Work toward win-win situation. Win-lose
Trondheim, Norway           is where you win and the other lose.
http://www.soiland.no/      Lose-lose and lose-win are left as an
                            exercise to the reader.  [Limoncelli/Hogan]



More information about the Mod_python mailing list