[mod_python] Package notation in PythonHandler directive

Gregory (Grisha) Trubetskoy grisha at modpython.org
Mon Aug 19 08:32:26 EST 2002


You might need an __init__.py file in subdir in order for this to work.

On 19 Aug 2002, Fabian Fagerholm wrote:

> Continuing to explore mod_python, I'm having trouble with package
> notation in the PythonHandler directive.
>
> I'm looking at the mod_python docs, and the Tutorial section 3.2 in
> particular. It suggests that you could have a directory structure as
> follows:
>
> <your base dir>
>   |
>   +- .htaccess (file)
>   +- subdir (directory)
>       |
>       +- myscript.py (file)
>
> The .htaccess file would look as follows:
>
>     AddHandler python-program .py
>     PythonHandler subdir.myscript
>
> and the myscript.py file in the 'subdir' subdirectory would look as
> follows:
>
>     from mod_python import apache
>
>     def handler(req):
>         req.content_type = "text/plain"
>         req.send_http_header()
>         req.write("Hello, World!")
>
>         return apache.OK
>
> If I do this, I get a 500 Internal Server Error and the following
> appears in the apache logs:
>
>     [Mon Aug 19 12:12:57 2002] [error] PythonHandler subdir.myscript:
>     Traceback (most recent call last):
>     [Mon Aug 19 12:12:57 2002] [error] PythonHandler subdir.myscript:
>     File "/usr/lib/python2.1/site-packages/mod_python/apache.py", line
>     181, in Dispatch
>         module = import_module(module_name, _req)
>     [Mon Aug 19 12:12:57 2002] [error] PythonHandler subdir.myscript:
>     File "/usr/lib/python2.1/site-packages/mod_python/apache.py", line
>     332, in import_module
>         f, p, d = imp.find_module(parts[i], path)
>     [Mon Aug 19 12:12:57 2002] [error] PythonHandler subdir.myscript:
>     ImportError: No module named subdir
>
> What am I doing wrong?
>
> Cheers,
> Fabian
>
>
> _______________________________________________
> 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