template is calling 2 times

S

sanjeevdivekar

hi,

i am newbie to python so i am trying to learn mod_python as my new
development kit for my small web apps.

i am getting strange result can anybody explain me.
*********************************************************************************************
index.py
*********************************************************************************************
from mod_python import apache
from mod_python import psp
from mod_python import util

def index(req, para=None):
tmpl = psp.PSP(req, filename='a.html')
tmpl.run(vars = {'para':para})
tmpl.run()

def show_data(req, name):
index(req, name)
*********************************************************************************************

*********************************************************************************************
a.htm
*********************************************************************************************

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
</HEAD>
<BODY>
<h1><%=para%></h1>
<form method="post" action="http://localhost:8080/test/show_data">
<input type="text" name="name">
<input type="submit">
</form>
</BODY>
</HTML>
*********************************************************************************************

*********************************************************************************************
Result
*********************************************************************************************
None
<textbox> <submitbutton>

Mod_python error: "PythonHandler mod_python.publisher"
Traceback (most recent call last):
File "E:\Python24\Lib\site-packages\mod_python\apache.py", line 299, in
HandlerDispatch result = object(req)
File "E:\Python24\Lib\site-packages\mod_python\publisher.py", line 213,
in handler published = publish_object(req, object)
File "E:\Python24\Lib\site-packages\mod_python\publisher.py", line 412,
in publish_object return Publish_object(req,util.apply_fs_data(object,
req.form, req=req))
File "E:\Python24\lib\site-packages\mod_python\util.py", line 439, in
apply_fs_data return object(**args)
File "E:\Apache Group\Apache2\htdocs\test\index.py", line 8, in index
tmpl.run()
File "E:\Python24\Lib\site-packages\mod_python\psp.py", line 213, in
run exec code in global_scope
File "E:\Apache Group\Apache2\htdocs\test\a.html", line 1, in ?
NameError: name 'para' is not defined
********************************************************************************************


what's wrong in this code?
any good internet resource to learn mod_python?

thanks in advanced
Sanjeev
 
B

Bruno Desthuilliers

sanjeevdivekar a écrit :
hi,

i am newbie to python so i am trying to learn mod_python as my new
development kit for my small web apps.

i am getting strange result

Nothing strange here AFAICT.
can anybody explain me.
index.py
*********************************************************************************************
from mod_python import apache
from mod_python import psp
from mod_python import util

def index(req, para=None):
tmpl = psp.PSP(req, filename='a.html')
tmpl.run(vars = {'para':para})
tmpl.run()

Here, you call tmpl.run() two time, the first time with a dict having an
entry named 'param', the second time without it.
a.htm
********************************************************************************************* (snip)
<BODY>
<h1><%=para%></h1>

And here you try to display something named "para". I don't have much
knowledge of PSP, but I have enough experience to assert this try to get
the entry named "param" from the dict passed to tmpl.run().

(snip)
Result (snip)
File "E:\Apache Group\Apache2\htdocs\test\index.py", line 8, in index
tmpl.run()

Here we are : line 8 of index.py, your second call to tmpl.run() without
the dict.
File "E:\Python24\Lib\site-packages\mod_python\psp.py", line 213, in
run exec code in global_scope
File "E:\Apache Group\Apache2\htdocs\test\a.html", line 1, in ?
NameError: name 'para' is not defined

and here the tentative to get this name from the dict.

Doesn't seem so strange to me. Note that I could be wrong - you'd better
check in PSP documentation - but I think I'd try commenting out the
second (and AFAICT useless) call to tmpl.run().
 

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,769
Messages
2,569,582
Members
45,067
Latest member
HunterTere

Latest Threads

Top