[mod_python] other file than .py

Graham Dumpleton grahamd at dscpl.com.au
Tue Jun 20 01:48:33 EDT 2006


elekis wrote ..
> hi,
> 
> I continue my little way in the magic world of python script under web
> and after installeing, testing and begin really to program a
> interractive site , I confronted with a little problem. I cannot touch
> other file than .py
> 
> exemple. there is my .htaccess
> 
> ----------------------------------
> SetHandler mod_python
> PythonHandler mod_python.publisher
> PythonDebug On
> ----------------------------------
> 
> 
> here is my event.css
> 
> --------------------------------
> h6 { font-size: 50pt ; }
> -------------------------------
> but when he trie to load the event.css I have a 500 error
> 
> -->http://localhost/public_html/add_event.css and it's the same thing
> for other file. is there a thing than I must put on my htacces???

Use "AddHandler" instead of "SetHandler" directive. For example:

  AddHandler mod_python .py
  PythonHandler mod_python.publisher

What this says is that only requests with a .py in URL will be routed
through to mod_python.publisher and not every request in that
directory. This will allow you to place .css, .html, .jpg, .gif, etc files
in the same directory.

Depending on which version of mod_python you are using, you should
also use:

  <Files *.pyc>
  deny from all
  </Files>

For older versions of mod_python this will ensure that compiled Python
byte code files are not downloadable. In mod_python 3.2.X these byte
code files are no longer generated for mod_python.publisher but can
for basic handlers, but still good to use it regardless.

> other thing. I very like the publisher mod.  cause we
> http://localhost/public_html/balbla/ link (and that 's cool.

If you are talking about the ability to not have .py in the URL, ie the
multiviews feature of Apache, then you also need to include additional
configuration to get it to work when using the AddHandler directive.
These additional directives are:

  Options +MultiViews
  MultiviewsMatch Handlers

  AddType text/html;qs=1.0 .py
  AddType text/html;qs=0.9 .html
  AddType text/plain;qs=0.8 .txt

If you don't have this, you will find that you can't leave off the .py
in the URL. Note that you may have to have Apache 2.0 and most
recent version of mod_python (3.2.X) for this all to work properly.

One last issue with using "AddHandler" over "SetHandler". When
using "SetHandler", mod_python.publisher will automatically map
a request against a directory to the 'index.py' file in the directory.
When using "AddHandler" this will not happen by default. If you
want this to happen, you must also include:

  DirectoryIndex index.py

This will cause Apache to take 'index.py' as a candidate index
directory when request is against the directory.

In summary, use the configuration:

  AddHandler mod_python .py
  PythonHandler mod_python.publisher
  PythonDebug On

  <Files *.pyc>
  deny from all
  </Files>

  Options +MultiViews
  MultiviewsMatch Handlers

  AddType text/html;qs=1.0 .py
  AddType text/html;qs=0.9 .html
  AddType text/plain;qs=0.8 .txt

  DirectoryIndex index.py

> but on modpython.org they say that is not the fastest way.
> 
>  Standard CGI:               23 requests/s
>     Mod_python cgihandler:     385 requests/s
>     Mod_python publisher:      476 requests/s
>     Mod_python handler:       1203 requests/s
> 
> is it possible to have the publisher link mod and the handler request???

Both mod_python.publisher and mod_python.cgihandler are merely
instances of mod_python handlers. There are slower because of the
extra work they do on top of the basic handler interface.

I would suggest you don't worry about speed issues, most sites do not need
to be blindingly fast and you are probably going to have enough to contend
with as it is, plus find it fast enough anyway.

FWIW, those figures were probably based on really old hardware as well
and can be ignored due to that fact. New hardware should perform much
better.

Graham


More information about the Mod_python mailing list