combining mod_python handlers publisher and psp problem

E

exhuma.twn

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/2004/02/26/python_server_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?
 
E

exhuma.twn

exhuma.twn said:
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/2004/02/26/python_server_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
 
G

grahamd

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
 
E

exhuma.twn

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top