473,473 Members | 1,997 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

template is calling 2 times

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
1 1092
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Rolf Kemper | last post by:
Dear All, somehow I remember that such or similar question was discussed already somewhere. But I can't find it anymore. I have a template calling itself. As long it goes deeper into the...
7
by: Patrick Kowalzick | last post by:
Dear all, I just wondered if it is possible to count the number of classes created via a template class at compile time. To show what I mean I post an example, which is not working but carries...
0
by: Tony Johansson | last post by:
Hello! Here I have two classes these are called Handle and Body and a main. You have the class definition below. Some basic information. In the Handle class is there a pointer to the Body class....
22
by: Ian | last post by:
The title says it all. I can see the case where a function is to be called directly from C, the name mangling will stuff this up. But I can't see a reason why a template function can't be...
0
by: Steve Jorgensen | last post by:
In a schema I've been working on recently, a convention I evolved was to use a consistent naming pattern such that, for instance, a Resident could appear in a ResidentSet, and could be referred to...
6
by: Neal | last post by:
Hi All, I used an article on XSLT and XML and creating a TOC written on the MSDN CodeCorner. ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/dncodecorn/html/corner042699.htm However, it did'nt...
0
by: magicofureyes | last post by:
Hello Guys im a just a new user and i dnt knw much abt Xml i want to upload a new template in Blogger so got some free coding but when i save this code in Blogger template it say '''' Your...
13
by: mike b | last post by:
Hello everyone, thanks in advance for your help. I'm new to C++ templates and have run into some issues using member function templates. I have a shared library containing templates that I'm...
0
by: shai.halevi | last post by:
I'm looking for a simple template with the following property: I want to have in the resulting page something like this (say): <div> This is some text that never changes: ]] This is some more...
6
by: Gaijinco | last post by:
I'm trying to do a template class Node. My node.hpp is: #ifndef _NODE_HPP_ #define _NODE_HPP_ namespace com { namespace mnya { namespace carlos { template <typename T>
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
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.