[mod_python] Simple Issue, Baffling

David Worley dworley at communityconnect.com
Thu Jan 26 15:13:19 EST 2006

Hello, all. I'm new to mod_python and somewhat new to server side

I've read the documentation, and I can't seem to find out something
relatively simple.

I'm writing a CSS preprocessor. It's meant to grab a request for a .css
file, process another file and return the result to the browser. The
issue I have is that I can't get the handler to return content the
browser actually uses.

To clarify, I'm running Apache 2.0, Python 2.4 on Windows XP.

So with the following httpd.conf entry:

<Directory /some/file/system/directory>
	AddHandler python-program .sss
	PythonHandler switch
	PythonDebug On

And the following Python code, in switch.py:

from mod_python import apache

def handler(req):
	req.content_type = "text/css"
body { background-color: red; }""")
	return apache.OK

This works. It works great. When I request
http://localhost/some/file/system/directory/style.css, I get the body
declaration above. BUT the browser doesn't use it!

I have the same problem when declaring req.content_type = "text/html":
the code is returned properly, but it isn't rendered as HTML. It's just
text, as far as the browser is concerned.

Please let me know if I've totally missed something simple in the
documentation, or misunderstood the handlers, or whatever it is I've
done wrong.


David Worley
Senior Front End Developer
dworley at communityconnect.com

More information about the Mod_python mailing list