Daniel Nogradi
nogradi at gmail.com
Thu May 4 08:05:58 EDT 2006
> > As Graham pointed out SetHandler and AddHandler should not be used at > > the same time. "SetHandler mod_python" causes all files to be served > > by mod_python and when you refer to them in your browser you don't > > need to specify any extension such as .py and "AddHandler mod_python > > .py" causes all files ending in .py to be served by mod_python but in > > this case when referring to a file in your browser you should add the > > .py extension. So if you have > > > > <Directory '/your_document_root/whatever'> > > SetHandler mod_python > > PythonHandler mod_python.publisher > > </Directory> > > > > and you have a file /whatever/foo.py with a function bar( ) then in > > your browser you would type http://yourserver/whatever/foo/bar, > > When using SetHandler you should still be able to use: > > http://yourserver/whatever/foo.py/bar > > Your mileage may vary though depending on how some of the > other bits of Apache configuration are set. See some of previous > rants for possibly useful about this. > > http://www.modpython.org/pipermail/mod_python/2005-August/018828.html > http://www.modpython.org/pipermail/mod_python/2005-August/018829.html > http://www.modpython.org/pipermail/mod_python/2006-March/020501.html > > > whereas with > > > > <Directory '/your_document_root/whatever'> > > AddHandler mod_python .py > > PythonHandler mod_python.publisher > > </Directory> > > > > you would need http://yourserver/whatever/foo.py/bar > > As long as you have content negotiation directives set correctly, you > don't have to use .py extension when AddHandler is used. See my linked > rants above for details. > > > So it's really up to you which behaviour you like, you want *all* > > files to be served by mod_python or only those that have a specific > > extension and then you set either AddHandler or SetHandler. But not > > both :) And in any case, you certainly don't want your .pyc files to > > be served at all, so you should probably remove "AddHandler mod_python > > .pyc". > > If using AddHandler and Apache has write permission to directory, it is > actually a good idea to have: > > <Files *.pyc> > deny from all > </Files> > > This will prevent the pyc files being accessible. > > Using AddHandler for pyc extension will probably actually cause it to > execute the file as publisher, just like if py extension was used. > This is > because mod_python.publisher will quite happily drop the pyc extension > and use basename to match to .py file. > > Besides the fact that AddHandler allows you to mix other file types in > the same directory, the main difference between SetHandler and > AddHandler > as far as mod_python.publisher goes is that when SetHandler is used a > request against the directory is passed through direct to > mod_python.publisher > and it resolves request to index.py. > > When AddHandler is used, a request against the directory results in > mod_dir > trying to match for a file listed in DirectoryIndex directive. In > order for > mod_python.publisher to be triggered, you would need to list index.py > in the DirectoryIndex directive. > > Other than that, with the correct Apache directives defined related > to content > negotiation, both ways should allow for optional use of extension. Thanks for these clarifications, I indeed didn't realize that my rule of thumb 'AddHandler: extension needed' vs. 'SetHandler: no extension' is not quite true. Probably my particular configuration gave me the feeling that it is always the case, but good to know that it isn't :)
|