[mod_python] Try # 2: Mod_python.publisher behavior - sending .py file to browser - Still !

Graham Dumpleton grahamd at dscpl.com.au
Sun May 7 04:09:43 EDT 2006


As a workaround for now, use the following for .htaccess file:

   SetHandler mod_python
   PythonHeaderParserHandler index::_fixup_directory
   PythonHandler mod_python.publisher
   PythonDebug On

and in index.py file put:

   from mod_python import apache
   import os, posixpath

   def _fixup_directory(req):
       if os.path.isdir(req.filename):
           if req.filename[-1] == '/':
               path = posixpath.join(req.uri, 'index.py')
               req.internal_redirect(path)
               return apache.DONE
       return apache.OK

   def index(req):
           req.write("I am in index()")

   def bar(req):
           req.write("I am in bar()")

Right now I'm not quite sure why it is mucking up but I'll look into it
further.

Graham

On 07/05/2006, at 5:24 PM, Geoff Skerrett wrote:

>
> Gentlemen thanks for you help, and I hope you will be patient with  
> me.  I
> have solved the problem and while I know why it works, I am not  
> sure why my
> solution was required as the documentation and your responses don't  
> seem to
> suggest it as being needed.
>
> Explaination:
> I modified the settings in my http.conf file for the directory as  
> suggested
> and of course restarted the server.  For this directory the setting  
> are now
> as follows;
>
> <Directory "C:\Program Files\Apache Group\Apache2\htdocs\app/">
>     SetHandler mod_python
>     PythonHandler mod_python.publisher
>     PythonDebug On
> </Directory>
>
> I created a very simple program index.py program to help me  
> understand the
> behavior.
> It is as follows;
>
> ### Begin index.py
>
> def index(req):
> 	req.write("I am in index()")
> 	
> def bar(req):
> 	req.write("I am in bar()")
>
> ### End index.py
>
> In the browser if I type the following Http://localhost/app/index
> The browser displays: "I am in index()"
>
> In the browser if I type the following Http://localhost/app/index/bar
> The browser displays: "I am in bar()"
>
> In the browser if I type the following Http://localhost/app/bar
> The browser displays: "I am in bar()"
>
> However ...
> In the browser if I type the following Http://localhost/app/
> The brower displays the file download page and says it is trying to  
> open a
> "httpd/unix-directory" file.  If I save this file and view it, the  
> contents
> are:
> "I am in index()"
>
> So ... mod_python.publisher appears to be working correctly for all  
> cases,
> except in the case where I think that it should automatically  
> default to
> finding function "index()" within the module "index.py".
>
> If I modify my example program as follows;
>
> ### Begin index.py
>
> def index(req):
> 	req.content_type = "text/plain"
> 	req.write("I am in index()")
> 	
> def bar(req):
> 	req.write("I am in bar()")
>
> ### End index.py
>
> Then the URI Http://localhost/app/ work file and displays "I am in  
> index()
> in the browser.
>
> So after that long winded explanation ... Is there an addition/ 
> extra setting
> in the http.conf file that I should be making to make the URI  
> resolution
> work properly without having to set the content_type ?  As I  
> mentioned at
> the top, the docs don't seem to suggest the *content_type* setting  
> as being
> a requirement.
>
> Glad I got I working though ... Now off to some more serious  
> development
> issues !
>
> Geoff.
>
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python



More information about the Mod_python mailing list