[mod_python] another beginners question: problem with <Location> directive

Gregory (Grisha) Trubetskoy grisha at modpython.org
Wed Nov 27 18:55:46 EST 2002


Mod_python adds the directory to sys.path for you, this is how Python
finds the script. But when you <Location> there is no way for mod_python
to know what to add to sys.path, so you have to do it explicitely, using
the PythonPath directive, try this:

<Location /python>
  AddHandler python-program .py
  PythonHandler mptest
  PythonPath "['/var/www/html/python']+sys.path"
  PythonDebug On
</Location>

Grisha

On 26 Nov 2002, Markus Jais wrote:

> hello
> I have the example from the tutorial
>
> from mod_python import apache
>
> def handler(req):
>     req.content_type = "text/html"
>     req.send_http_header()
>     req.write("Eagles are great")
>     return apache.OK
>
> and this setup
>
> <Directory /var/www/html/python>
>   AddHandler python-program .py
>   PythonHandler mptest
>   PythonDebug On
> </Directory>
>
>
> this works fine.
>
> but when I change the <Directory> directive to
> ----
> <Location /python>
>   AddHandler python-program .py
>   PythonHandler mptest
>   PythonDebug On
> </Location>
> ---
> I get this error in my apache logfile:
> [Tue Nov 26 00:07:18 2002] [notice] mod_python: (Re)importing mptest from None
> [Tue Nov 26 00:07:18 2002] [error] PythonHandler mptest: Traceback (most recent call last):
> [Tue Nov 26 00:07:18 2002] [error] PythonHandler mptest:   File "/usr/local/lib/python2.2/site-packages/mod_python/apache.py", line 181, in Dispatch
>     module = import_module(module_name, _req)
> [Tue Nov 26 00:07:18 2002] [error] PythonHandler mptest:   File "/usr/local/lib/python2.2/site-packages/mod_python/apache.py", line 332, in import_module
>     f, p, d = imp.find_module(parts[i], path)
> [Tue Nov 26 00:07:18 2002] [error] PythonHandler mptest: ImportError: No module named mptest
>
>
> I am using python 2.2.2, modpython 2.7.8 and apache 1.3.23 (rpm version for redhat 7.3)
>
> markus
>
>
>
> __________________________________________________________________
>
> Gesendet von Yahoo! Mail - http://mail.yahoo.de
> MЖchten Sie mit einem Gruъ antworten? http://grusskarten.yahoo.de
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://www.modpython.org/mailman/listinfo/mod_python
>




More information about the Mod_python mailing list