Friday, March 4, 2011

mod_python.publisher always gives content type 'text/plain'

I've just set up mod python with apache and I'm trying to get a simple script to work, but what happens is it publishes all my html as plain text when I load the page. I figured this is a problem with mod_python.publisher, The handler I set it too. I searched through the source of it and found the line where it differentiates between 'text/plain' and 'text/html' and it searches the last hundred characters of the file it's outputting for ' in my script, so I put it in, and then it still didn't work. I even tried commenting out some of the code so that publisher would set everything as 'text/html' but it still did the same thing when I refreshed the page. Maybe I've set up something wrong.

Heres my configuration in the httpd.conf

< Directory "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs">
SetHandler mod_python
PythonHandler mod_python.publisher
PythonDebug On
< /Directory >

From stackoverflow
  • Your configuration looks okay: I've got a working mod_python.publisher script with essentially the same settings.

    A few other thoughts:

    • When you tried editing the publisher source code, did you restart your web server? It only loads Python libraries once, when the server is first started.

    • Publisher's autodetection looks for a closing HTML tag: </html>. Is that what you added? (I can't see it in your question, but possibly it just got stripped out when you posted it.)

    • If nothing else works, you can always set the content type explicitly. It's more code, but it's guaranteed to work consistently. Set the content_type field on your request to 'text/html'.

    For example, if your script looks like this right now:

    def index(req, an_arg='default'):
        return some_html
    

    it would become:

    def index(req, an_arg='default'):
        req.content_type = 'text/html'
        return some_html
    

0 comments:

Post a Comment