John Dean said:
I have fixed my problem with mod_python. I have one small problem left to
sort out. If I enter the URL
http://localhost Apache just displays the
contents of the htdocs directory, but if I enter the URL
http://localhost/test.py everything works as it should. I guess this is
somewhat off topic since it appears to be an Apache configuration problem so
I hope you don't mind me asking you for your opinion on c.l.p.
Well, I get around this problem by adding "index.py" to the DirectoryIndex
directive. I use a modified version of the publisher module that comes with
mod_python that handles this and related special cases. Here's the change
that I make, if you're interested:
< if not _req.subprocess_env.has_key("PATH_INFO"):
< raise apache.SERVER_RETURN, apache.HTTP_NOT_FOUND
<
< func_path = _req.subprocess_env["PATH_INFO"][1:] # skip fist /
< func_path = string.replace(func_path, "/", ".")
---
if _req.subprocess_env.has_key("PATH_INFO"):
func_path = _req.subprocess_env["PATH_INFO"][1:] # skip first /
func_path = string.replace(func_path, "/", ".")
# If no function is specified, assume "default".
if not len(func_path): func_path = "default"
else:
# If no module is specified either, assume "index".
func_path = "default"
module_name = "index"
This has the result that "index" is always the default module, and "default"
is the function within that module that gets called if no function is
explicitly specified on the URL. This works like a charm.
BTW What I am trying to do is to move away from PHP. Since I use Python as
my primary scripting language for just about everything where you would use
a scripting language, it seems to me to be a reasonable idea to use Python
to provide dyanamic content for the web sites I look after.
I did the same thing myself last year, after writing PHP for a couple of
years. mod_python definitely makes Python a worthy substitute for writing
Apache modules. The main drawbacks from my experience are the lack of
built-in session handling and more sophisticated parameter passing (ie.
PHP's ability to serialize hashes from a form submission). But I'm a little
dated now, I'm still using mod_python 2 / apache 1.3 ...
Have fun,
Dave