[mod_python] Simple Issue, Baffling

David Worley dworley at communityconnect.com
Thu Jan 26 17:00:13 EST 2006

Mine is the same cross browser. I've tested in Firefox 1.5, MSIE 6.0,
and Opera (vWhoCaresItsOpera.0).

I'm surprised yours is browser-dependant.

David Worley
Senior Front End Developer
dworley at communityconnect.com

-----Original Message-----
From: mod_python-bounces at modpython.org
[mailto:mod_python-bounces at modpython.org] On Behalf Of Jim Steil
Sent: Thursday, January 26, 2006 4:56 PM
To: mod_python at modpython.org
Subject: Re: [mod_python] Simple Issue, Baffling

I have what I think is a similar problem.  My app works just fine with
IE, but when I try to get at it with FireFox, I see my HTML source
instead of my app.  I'm really new to all this, so it may not be
related.  But, I'm watching for a resolution as I'm hoping it will clue
me in to what I'm doing wrong as well.  It happens to me with Firefox


Jim Gallacher wrote: 

	David Worley wrote: 

		To clarify further: 
		http://localhost/some/file/system/directory/style.css is
only ever 
		called from an HTML file, via a <link> tag. 

	I figured you knew that, but one never knows. ;) 

		The HTML is valid. The HTML 
		page is NOT generated by mod_python. It's just a plain
HTML file in the 
		folder. I created it just for testing dynamically
created CSS files. 
		The separate issue of "text/html" content is, indeed,
handled by another 
		handler. The two are unrelated. When text/css content
wouldn't work, I 
		tried something simpler: plain HTML return content. 
		Simply put, req.write(xxx) returns content that my
browser does not make 
		use of, whether CSS or HTML, despite the explicit
declaration of 
		req.content_type. The browser just thinks it's text. 
		It may be more accurate to say that the server never
returns HTML or 
		CSS, rather than saying that the browser never renders
the file 

	Is your handler as simple as you indicated or is there other
stuff going on? Any chance you are calling req.write *before* setting
req.content_type? The first call to req.write triggers the sending of
the response headers, which contains the Content-Type header. Once
you've starting calling req.write changing req.content_type will have no
effect. (Hmm, I wonder if we should actually raise an exception... ) 
	I find that tools like wget or netcat are helpful for this sort
of thing since you can dump the response headers as well as the page
content. If you don't have ready access to these programs I'm sure you
could know somthing together from the standard python lib. Sometimes the
simplest problems have the simplest solutions. 

		David Worley 
		Senior Front End Developer 
		dworley at communityconnect.com 
		-----Original Message----- 
		From: Jim Gallacher [mailto:jpg at jgassociates.ca] Sent:
Thursday, January 26, 2006 4:15 PM 
		To: David Worley 
		Cc: mod_python at modpython.org 
		Subject: Re: [mod_python] Simple Issue, Baffling 
		David Worley wrote: 

			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 


			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

		Maybe I don't understand the question but why would it?
The browser only 
		uses the stylesheet to render the page when it's
specified in an html <style> tag. 

			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 


			text, as far as the browser is concerned. 

		You got me there, unless you are saying you are getting
the python code as opposed to the html you send with req.write. Are you
writing valid html? Any chance there is a typo in req.content_type =
'text/html'? Are you using a different handler for generating the html? 
		It would help if you can clarify your problem a little. 
		Mod_python mailing list 
		Mod_python at modpython.org 


	Mod_python mailing list 
	Mod_python at modpython.org 

Jim Steil
IT Manager
Quality Liquid Feeds
(608) 935-2345

More information about the Mod_python mailing list