Tuesday, March 07, 2006

 

Basic FOR loops

.tmpl file is:

Content-type: text/html

<html>
<h2>You sent signal=$signalval</h2>
#for $item in $l_list:
$item <br>
#end for
</html>

cheetah_test.cgi is:

#!/usr/bin/python

from Cheetah.Template import Template
import cgi

# Gather the entries from the form.
try:
The_Form = cgi.FieldStorage()
except:
print "cgi error"
sys.exit()

try:
signal = The_Form['signal'].value
except:
# If user doesn't supply a signal value, set to 'start'.
signal = 'start'

l = [1,2,3,4,5,10]
mydict = {'signalval': signal,
'l_list': l}
t = Template(file='cheetah_test.tmpl', searchList=[mydict])
print t

Comments: Post a Comment



<< Home

This page is powered by Blogger. Isn't yours?