[ZPT] passing data from python script to zpt field

Ian Bicking ianb at colorstudy.com
Thu Nov 13 11:25:19 EST 2003


On Nov 13, 2003, at 10:06 AM, Tom P. Allred wrote:
> Can anyone point to a resource or give an example of how to fill in a 
> zpt
> form field with data from a python script?  I have a form with several
> fields and would like some of those fields to be preloaded with data
> gathered in a python script.  The data will vary each time I present 
> the
> form.

Python Script:
return container['page.pt'](field1=something, field2=something)

ZPT:

<input type="text" name="field1" tal:attributes="value options/field1">

Or if you want to handle errors:

return container['page.pt'](field1=something, errors = {'field1': 'yada 
yada'},
     field2=something)

(the form action points back to your Python script, with some hidden 
field meaning that it should process form results)

<div class="error" tal:condition="options/errors/field1 | nothing" 
tal:content="options/errors/field1">error</div>
<input type="text" name="field1" tal:attributes="value request/field1 | 
options/field1">

--
Ian Bicking | ianb at colorstudy.com | http://blog.ianbicking.org




More information about the ZPT mailing list