[mod_python] Joining template objects

Dagur Páll Ammendrup dagurp at heimsnet.is
Mon Nov 8 13:29:15 EST 2004


I ended up doing that too. Thanks though :-)



Daniele Cruciani wrote:

>Yes, because I was wrong, sorry.
>
>try in other way. (put the code in template)
>
>Sorry, I am new to modpython, what I propose to you is what I want to
>make myself. Right now I have used a dirty way:
>
><%
>for i in range(int(begin),min(int(begin)+ncom,last+1)):
>    out="""
><tr>
><td>
><span style="font-size: 13px;font-family:courier;text-decoration:underline;">%s</span> il %s era %s e ha scritto:
></td>
></tr>
><td style="border: thin dashed #FFdeFF;background-color:#dddddd">%s
></td>
></tr>
><tr><td>
><hr align="center" width="30%%" noshade size="1">
></td>
></tr>
>""" % (commenti[i]['nome'],commenti[i]['data'],statodanimo[commenti[i]['sda']],commenti[i]['commento'])
>    req.write(out)
># (end for)
>%>
>
>(this is for http://fincos.homeip.net/ )
>
>I just used a formatted text, you can make use your person.html as
>template in your code, but I do not know how to use psp.PSP class,
>documentation is your power.
>
>Daniele.
>
>On Sun, Nov 07, 2004 at 10:34:42PM +0000, Dagur Páll Ammendrup wrote:
>  
>
>>I tried that but I get:
>>
>>TypeError: cannot concatenate 'str' and 'instance' objects
>>
>>
>>Daniele Cruciani wrote:
>>
>>    
>>
>>>Hi,
>>>
>>>simply bottom-up way:
>>>
>>>people=''
>>>for p in peopledict:
>>>	# call psp.PSP for each person
>>>	dic={'name':p['name'],....}
>>>	people=people+ psp.PSP(req,'person.html',vars=dic)
>>>
>>>dic={'people':people}
>>>yourpage=psp.PSP(req,'people.html',vars=dic)
>>>
>>>and return it, or you can do it inside the people template or make a
>>>function which return parsed person-s, called people a call it from
>>>people.html template
>>>
>>>Daniele.
>>>
>>>On Sat, Nov 06, 2004 at 10:12:57PM +0000, Dagur Páll Ammendrup wrote:
>>>
>>>
>>>      
>>>
>>>>I have a complete beginners question for you.
>>>>Here's a stupid example but I hope it explains what I'm trying to do. 
>>>>Let's say I have this template
>>>>
>>>>people.html
>>>>
>>>>|<h2>
>>>>Here is a list of people
>>>><%= people %>
>>>></h2>|
>>>>
>>>>Then there's another template:
>>>>
>>>>person.html
>>>>
>>>>|<p>
>>>>Name: <%= name %>
>>>>Occupation: <%= job %>
>>>>Email <%= email %>
>>>></p>|
>>>>
>>>>Now let's say I want to use person.html on a list of several people and 
>>>>I use psp.PSP() to do it.
>>>>How can I join the objects together and put them into the single 
>>>>'people' varible for the outer 'people.html' template so I get this?
>>>>
>>>>
>>>>|<h2>
>>>>Here is a list of people
>>>>|
>>>>|<p>
>>>>Name: John
>>>>Occupation: programmer
>>>>Email john at microsoft.com
>>>></p>||
>>>>
>>>>||<p>
>>>>Name: Steven
>>>>Occupation: Student
>>>>Email steven at fbi.com
>>>></p>
>>>>
>>>>..etc
>>>>
>>>>||</h2>
>>>>
>>>>|
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>_______________________________________________
>>>>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