473,399 Members | 2,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

combining mod_python handlers publisher and psp problem

Simple problem:

When I define a funtion the way you would with the publisher handler
(without using psp), all works as expected. However when I define a
publisher-like function and instantiate a PSP object in it ( as
suggested on
http://www.onlamp.com/pub/a/python/2...ver_pages.html
) mod_python seems to fail to tell the browser which content-type the
document has. The output is what I expect it to be, but instead of
rendering the page I see the source code, so I suppose the browser sees
it as "text/python" or "text/plain".

I tried to do a

print "Content-Type: text/html"
print

as first statement, but then it only outputs that as normal text too.

Any ideas?

Mar 20 '06 #1
3 1468
exhuma.twn wrote:
Simple problem:

When I define a funtion the way you would with the publisher handler
(without using psp), all works as expected. However when I define a
publisher-like function and instantiate a PSP object in it ( as
suggested on
http://www.onlamp.com/pub/a/python/2...ver_pages.html
) mod_python seems to fail to tell the browser which content-type the
document has. The output is what I expect it to be, but instead of
rendering the page I see the source code, so I suppose the browser sees
it as "text/python" or "text/plain".

I tried to do a

print "Content-Type: text/html"
print

as first statement, but then it only outputs that as normal text too.

Any ideas?


Update:
I got it working. My old code was as follows:

def index(req, name='John'):
s = 'Hello, there!'
if name:
names = ['a', 'b', 'c']
s = 'Hello, %s!' % name.capitalize()
tmpl = psp.PSP(req, filename='index.psp')
tmpl.run(vars = { 'greet': s, 'names': names })
return

Now I did this:

def index(req, name='John'):
s = 'Hello, there!'
if name:
names = ['a', 'b', 'c']
s = 'Hello, %s!' % name.capitalize()
tmpl = psp.PSP(req, filename='index.psp',
vars = { 'greet': s, 'names': names })
return tmpl

So basically I assigned the variables on instantiation of the PSP
object and returned the resulting reference. This is different to what
is noted at onlamp.com

Mar 20 '06 #2
You could also have done:

def index(req, name='John'):
s = 'Hello, there!'
if name:
names = ['a', 'b', 'c']
s = 'Hello, %s!' % name.capitalize()
tmpl = psp.PSP(req, filename='index.psp')
req.content_type = 'text/html'
tmpl.run(vars = { 'greet': s, 'names': names })
return

Try the mod_python mailing list if you want an explaination of why.

Graham

Mar 20 '06 #3

gr*****@dscpl.com.au wrote:
You could also have done:

def index(req, name='John'):
s = 'Hello, there!'
if name:
names = ['a', 'b', 'c']
s = 'Hello, %s!' % name.capitalize()
tmpl = psp.PSP(req, filename='index.psp')
req.content_type = 'text/html'
tmpl.run(vars = { 'greet': s, 'names': names })
return

Try the mod_python mailing list if you want an explaination of why.

Graham


Thanks, that worked.

Mar 20 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Doug Farrell | last post by:
Hi all, I'm trying to build a demonstration website using mod_python and 4Suite to show how we could transform XML documents into HTML with XSLT. Here is a piece of code that causes it to blow...
3
by: Rune Hansen | last post by:
I've posted this question on the mod_python mailing list but didn't get much response, so I thought I'd post it here. (My first attempt connected to an unrelated thread..sorry....
0
by: Julien Cigar | last post by:
Hello, I'm using mod_python 3.1.3 with Apache 2.0.54 on a Debian box with the publisher handler and the Clearsilver template engine, and from time to time apache returns an 500 error code...
6
by: Anthony L. | last post by:
I am writing a web application that is comparable to a content management system used in blogging. I really want to use Python after having done some evaluation coding using Python 2.3.5 with...
2
by: exhuma.twn | last post by:
Hi again, as soon as I try to make use of the "session" object inside a psp-template file, I get the following error: Mod_python error: "PythonHandler mod_python.publisher" Traceback (most...
4
by: John Salerno | last post by:
I get this internal error message when I try to access a PSP page: "Invalid command 'PythonHandler', perhaps mis-spelled or defined by a module not included in the server configuration" So it...
1
by: yaru22 | last post by:
I was reading Chapter 6.1 in mod_python manual at www.python.org. The manual simply says: The publisher handler is a good way to avoid writing your own handlers and focus on rapid application...
2
by: m.banaouas | last post by:
I installed Apache 2.2.3 and mod_python 3.2.10 on WinXP plateform I configured mod_python via httpd.conf: LoadModule python_module modules/mod_python.so but my script folder configuration...
1
by: jpuopolo | last post by:
Hi, all... I am hoping that someone can help me with the magic incantation to get mod_python working on my local machine. Set up: Apache 2.2.9, mod_python 3.3.1 on Windows Vista (yes, pity...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.