[mod_python] Problem with Mod Python Appending HTML

Graham Dumpleton grahamd at dscpl.com.au
Wed Jun 28 18:30:32 EDT 2006

Max Luebbe wrote ..
> I am having problems with my mod_python scripts appending HTML together,
> when having req.write() create a new page is what I am after.
> I have an authentication handler for a blank html page that queries a
> database for a user/pass, and then generates HTML based off of who
> logged in.

When you say you have a "authentication handler", do you mean that it
is triggered by PythonAuthenHandler directive. If it is and you are returning
HTML from it and it represents the complete response for the request,
you must return apache.DONE and not apache.OK. If you do not return
apache.DONE, the content handler will still be executed and thus any
HTML that the content handler itself generates will be appended to the

The only other time you would likely see HTML from two places being
concatenated together, is when you are generating HTML but then returning
an error status such as apache.HTTP_UNAUTHORIZED. In other words, 
you were wanting to generate a custom error response page. If you simply
return apache.HTTP_UNAUTHORIZED in that situation, then Apache will
still go on to generate an error document page which gets appended to
your output. In that situation you should instead use:

  req.status = apache.HTTP_UNAUTHORIZED
  # generate HTML
  return apache.OK

If this is a handler other than PythonHandler, again, you should be
returning apache.DONE and not apache.OK.

I would suggest that you post what your Apache configuration directives
are so it is clear what handlers are being executed and in what phases.

Show a cut done version of what your handlers are doing would also
be helpful.


> The HTML generated is a form, and the user information is used to
> populate the default values. When the user submits the form, and my
> formHandler is called, the HTML it generates is appended to the current
> page, instead of starting a new one. I have <html> and </html> tags at
> the appropriate places to mark where documents are starting and
> stopping.
> I did not have this problem on any of the other pages/scripts I have
> written, and I think that adding authentication into the mix is the
> variable in the equation.
> What I am after is the following sequence:
> (1) user login 
> (2) new page w/form with default fields grabbed from db (generated html)
> (3) another new page w/confirmation info (values and corrections from
> form) (generated html)
> Any suggestions?
> I would greatly appreciate any help I could get.
> -- 
> Max Luebbe <max.luebbe at gmail.com>
> _______________________________________________
> 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