[mod_python] Using Templates

Jim Gallacher jpg at jgassociates.ca
Wed Jul 11 09:09:22 EDT 2007


Hi Ron,

You'll need to show us the full traceback as there is not enough 
information to determine the problem. There may be a typo in your code, 
or is just in the email? Do you really have:

<%=loadMonth(req, =strDate)%>
                   ^
                  ???

Also you might want to put your python code in a block rather than 
enclosing each statement in "<%= %>". Doing this will make your code 
(and tracebacks) easier to read. ie

<%

from mod_python import apache, psp
from loadCalendar import loadMonth, strDate

loadPan()
loadMonth(req, strDate)

%>

Jim

ron banks wrote:
> Have been doing fine with mod_python and in the process of learning it.
> I can see the wisdom of utilizing templates.
> Here's where I establish my newbie status. Can someone tell me what I am
> doing wrong, how I should be doing it,
> or why I am not getting this. Be gentle, I set up my first web site
> using psp only recently and I have no experience
> with templates. Newbie status established. I have a function that builds
> the html to create a calendar that I will later
> populate with scheduling records. I'm just trying to get a calendar that
> the user can navigate back and forth by month
> so I will have a couple of buttons that will javascript a string with a
> date, "2007,7,11" using ajax to set a session variable.
> Then I want to run the same calendar function that will pick up this
> session variable and build a calendar based on the
> new date. I trying to figure out how to do this with templates. Here's
> an example:
> 
> -------------------------Month.psp-------------------------
> <%
> from mod_python import apache, psp
> from loadCalendar import setStrDate
> %>
> <%=setStrDate(req)%>
> 
> ----------------loadCalendar/setStrDate----------------
> def setStrDate(req):
> 	if not hasattr(req, 'session'):
> 		session = initSession(req)
> 		strDate = ""
> 	else:
> 		session = Session.Session(req)
> 		strDate = getSessionVariable(session, 'currDate')
> 	req.content_type = 'text/html'
> 	tmpl = psp.PSP(req, filename='Month.tmpl')
> 	tmpl.run(vars = {'strDate': strDate})
> 	return ""
> 
> ------------------------Month.tmpl-------------------------
> <%
> from mod_python import apache, psp
> from loadCalendar import loadMonth, strDate
> %>
> 
> <%=loadPan()%>
> <%=loadMonth(req, =strDate)%>
> 
> ----------------Traceback from psp.py-------------------
>   File "/var/www/html/TaskMaster/Month.tmpl", line 21
> 
> 
>     req.write("""
> 
> 
> """,0); req.write(str(loadPan()),0); req.write("""
> """,0); req.write(str(loadMonth(req, =strDate)),0); req.write("""
> 
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python



More information about the Mod_python mailing list