By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,764 Members | 1,389 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,764 IT Pros & Developers. It's quick & easy.

template is calling 2 times

P: n/a
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

Jul 7 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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().
Jul 7 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.