Mod_python.publisher always provides "text / plain" content type
I just installed a python mod with apache and I am trying to get a simple script to work, but what happens is it publishes all my html as plain text on page load. I figured it was a problem with mod_python.publisher, a handler that I installed too. I looked at its source and found the line where it distinguishes between "text / plain" and "text / html" and it looks for the last hundreds of characters of the file it outputs for "in my script, so I put it in, and then this still didn't work. I even tried commenting out some code to have the publisher set everything as "text / html" but it still did the same when I refreshed the page. Maybe I created something wrong.
Here is my config in httpd.conf
<Directory "C: / Program Files / Apache Software Foundation / Apache2.2 / htdocs">
SetHandler mod_python
PythonHandler mod_python.publisher
PythonDebug on
</Directory>
source to share
Your config looks ok: I have a working mod_python.publisher script with the same settings.
A few other thoughts:
-
When you tried to edit the publisher's source code, did you restart your web server? It only loads the Python libraries once, when the server is first started.
-
Publisher autodetection looks for the closing HTML: </html> tag. Is this what you added? (I don't see this in your question, but it may have just been stripped when you posted it.)
-
If nothing else works, you can always specify the content type explicitly. This is more code, but it is guaranteed to work consistently. Set the content_type field in your "text / html" request.
For example, if your script looks like this:
def index(req, an_arg='default'):
return some_html
it will become like this:
def index(req, an_arg='default'):
req.content_type = 'text/html'
return some_html
source to share