[mod_python] Source code displayed by Mozilla/Firefox

Daniel J. Popowich dpopowich at blue-fox.com
Mon Jun 6 10:39:07 EDT 2005


To clarify a few points made by Graham...

> On 06/06/2005, at 2:04 AM, Colin Doherty wrote:
> > I'm using mod_python servlets and psp and although the
> > code works correctly for IE, the source code of the
> > template is displayed with Mozilla and Firefox when
> > called from the servlet.
> >
> > I'm setting the content type within the servlet:
> >
> > class test(Servlet):
> >   content_type = 'text/html'
> >
> > and calling the template thus:
> >
> >   def respond(self):
> >     Servlet.respond(self)
> >     template = PSP(self.req, filename='test.html')
> >     template.run({'servlet':self})
> >     return True
> >
> > Any suggestions appreciated.
> 

> What is the URL you are using for the request? Are you using "test.mps",
> "test.html" or just "test" with no extension?
>
>    Options -MultiViews
>

mod_python servlets (mps) enforces "clean" urls, so the only way to
access a servlet in "test.mps" is with "test", so MultiViews, in my
experience, has to be turned off as Graham says. 

> for that part of the directory heirachy, and make sure you always use
> "test.mps" explicitly.

This is incorrect: using "test.mps" explicitly will fail and return a
404 error.

mps does the following for req.filename:

    1.  If it's a directory, "DIR," do a brute-force internal redirect
        to "DIR/index".

    2.  If the basename begins with "." or "_" return 403.  This
        allows you to co-locate data files or other python source
        without worry of being downloaded by prying eyes.  (Future
        versions may check every component of the path to see if it
        begins with "." or "_" so whole directory hierarchies can be
        forbidden.

    3.  If req.filename has an extension:
           a) if the extension is ".mps" return 404 (this is where
              "clean" urls are enforced).
	   b) otherwise return apache.DECLINED if the file
              exists, else 404.

    4.  If req.filename has no extension:

           a) if req.filename + ".mps" exists use it.
           b) otherwise return apache.DECLINED if the file
	      exists, else 404.

Note how mps returns apache.DECLINED for non ".mps" files...this
allows you to co-locate ANY mimetype: html, php, psp, jpg, gif,
etc. within a directory "handled" by mps.  In fact, you can set your
DocumentRoot to be handled by mps and all your content should be
handled as expected (except for MultiViews and the extra performance
hit of mps).

In otherwords, with MultiViews off you can co-locate test.mps,
test.html, test.php, test.psp all in the same directory without
failure.

> BTW, why specifically are you using mpservlets as when using PSP you may
> find they don't mesh very well? For example, one of the points of using
> mpservlets is that by supplying its own write/writeln methods in the
> servlet it does its own buffering of output. Because PSP is going to
> write direct to the request object using req.write(), the buffering in
> mpservlets is bypassed. Another reason people use mpservlets is that it
> has some session support, but then so does PSP.

<soapbox>
While output buffering and session handling are bonuses, the main
reason I wrote mps was to have an OO view of the web.  Writing an
abstract base class that manages the overall layout of a site and
then writing subclasses for specific pages is, imho, very powerful.
Also, being able to re-use base class features in every servlet
(particularly form/query variable processing) saves hours of
programming.
</soapbox>

Cheers,

Daniel Popowich
-----------------------------------------------
http://home.comcast.net/~d.popowich/mpservlets/


More information about the Mod_python mailing list