[mod_python] Using Templates

ron banks rebcoair at cfl.rr.com
Thu Jul 12 07:52:07 EDT 2007


Thanks for the reply. I do realize that the '=' is wrong. When removed
the browser just hangs without reporting errors. What I am not getting
is how to properly set the 'strDate' variable in:

<%=loadMonth(req, strDate)%>

with this function:
def setStrDate(req):
	session = Session.Session(req)
	if session.is_new():
		strDate = ""
		strDate = getSessionVariable(session, 'currDate')
	req.content_type = 'text/html'
	tmpl = psp.PSP(req, filename='Month.tmpl')
	tmpl.run(vars = {'strDate': strDate})
	return ""

called from:
from mod_python import apache, psp
from loadCalendar import setStrDate

How should this be done? This is a first experiment for me utilizing
templates. What I am trying to do is to set a session variable
'currDate' with a new date through ajax methods and load a page with the
same loadMonth function which builds a calendar populated with records
from a database backend. I have worked out almost everything else and
have only a couple of problems before I can move forward.

I either need to figure out how to utilize a template system as
described which I think might be preferable in this situation or
possibly reload the same page letting the loadMonth function pick up the
changed session variable and building the page based on the new date.
I'm not sure how to reload the page. Should I use some type of redirect
from the server side or javascript from the client side? I have only
started to experiment with these methods. I can't seem to get the
redirect to do anything yet.  With the javascript reload the session
variable seems to go away. Is this because of the new request or
something? Maybe a better method is to control session information in
the database and just use javascript. I don't know what differences in
speed would be. What do you think?

On Thu, 2007-07-12 at 13:22 +1000, Graham Dumpleton wrote:
> On 11/07/07, ron banks <rebcoair at cfl.rr.com> wrote:
> >   File "/var/www/html/TaskMaster/Month.tmpl", line 22
> >
> >     req.write("""
> >
> >
> > """,0); req.write(str(loadPan()),0); req.write("""
> > """,0); req.write(str(loadMonth(req, =strDate)),0); req.write("""
> Bad syntax caused by '=' before 'strDate' when used as argument to
> function. Everything between the '<%=' and '%>' must be valid Python
> code. You should not be sticking additional '=' in front of variable
> references.
> Graham

More information about the Mod_python mailing list