Loading ...
Sorry, an error occurred while loading the content.

[Cheetahtemplate-discuss] My first Template - Struggling with searchList

Expand Messages
  • Geoff Skerrett
    Trying to get my first template working. When I output the results I get the following error; File c: python23 Lib site-packages Cheetah NameMapper.py , line
    Message 1 of 3 , Dec 11, 2004
    • 0 Attachment
      Trying to get my first template working.
       
      When I output the results I get the following error;
       
       File "c:\python23\Lib\site-packages\Cheetah\NameMapper.py", line 193, in valueForKey
          return obj[key]
      TypeError: list indices must be integers
       
       
      The following is an example of the code I am trying to use;
      from Cheetah.Template import Template
      custlist=[]
      custlist.append({"custno":"abc","coname":"the Bigg club","osamt":"$1200"})
      custlist.append({"custno":"xyz","coname":"the Small club","osamt":"$2200"})
      custlist.append({"custno":"W123","coname":"Western club","osamt":"$400")
       
      t = """<html><body><table>
           #for $ecust in $custlist
          <tr><td>$ecust.coname</td><td>$ecust.osamt</td></tr>
           #end for
           </table></body></html>"""
       
      tmpl = Template(t,searchList[custlist])
      print tmpl
       
      The complete error:
       
      Traceback (most recent call last):
        File "<interactive input>", line 1, in ?
        File "<string>", line 29, in respond
        File "c:\python23\Lib\site-packages\Cheetah\NameMapper.py", line 250, in valueFromSearchList
          executeCallables=executeCallables, passNamespace=True)
        File "c:\python23\Lib\site-packages\Cheetah\NameMapper.py", line 219, in _valueForName
          binding = valueForKey(obj, firstKey)
        File "c:\python23\Lib\site-packages\Cheetah\NameMapper.py", line 193, in valueForKey
          return obj[key]
      TypeError: list indices must be integers
       
      Any help would be appreciated.
       
    • Ian Bicking
      ... I believe that should be like: tmpl = Template(t, searchList={ custlist : custlist}) -- Ian Bicking / ianb@colorstudy.com / http://blog.ianbicking.org
      Message 2 of 3 , Dec 11, 2004
      • 0 Attachment
        Geoff Skerrett wrote:
        > Trying to get my first template working.
        >
        > When I output the results I get the following error;
        >
        > File "c:\python23\Lib\site-packages\Cheetah\NameMapper.py", line 193,
        > in valueForKey
        > return obj[key]
        > TypeError: list indices must be integers
        >
        >
        > The following is an example of the code I am trying to use;
        > from Cheetah.Template import Template
        > custlist=[]
        > custlist.append({"custno":"abc","coname":"the Bigg club","osamt":"$1200"})
        > custlist.append({"custno":"xyz","coname":"the Small club","osamt":"$2200"})
        > custlist.append({"custno":"W123","coname":"Western club","osamt":"$400")
        >
        > t = """<html><body><table>
        > #for $ecust in $custlist
        > <tr><td>$ecust.coname</td><td>$ecust.osamt</td></tr>
        > #end for
        > </table></body></html>"""
        >
        > tmpl = Template(t,searchList[custlist])

        I believe that should be like:

        tmpl = Template(t, searchList={'custlist': custlist})

        --
        Ian Bicking / ianb@... / http://blog.ianbicking.org


        -------------------------------------------------------
        SF email is sponsored by - The IT Product Guide
        Read honest & candid reviews on hundreds of IT Products from real users.
        Discover which products truly live up to the hype. Start reading now.
        http://productguide.itmanagersjournal.com/
        _______________________________________________
        Cheetahtemplate-discuss mailing list
        Cheetahtemplate-discuss@...
        https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
      • Geoff Skerrett
        Thanks. Exactly what I was missing. ... From: Mike Orr [mailto:mso@oz.net] Sent: Saturday, December 11, 2004 9:18 PM To: Geoff Skerrett; Cheetah Template List
        Message 3 of 3 , Dec 11, 2004
        • 0 Attachment
          Thanks.
          Exactly what I was missing.


          -----Original Message-----
          From: Mike Orr [mailto:mso@...]
          Sent: Saturday, December 11, 2004 9:18 PM
          To: Geoff Skerrett; Cheetah Template List
          Subject: Re: [Cheetahtemplate-discuss] My first Template - Struggling with
          searchList

          On Sat, Dec 11, 2004 at 08:53:44PM -0400, Geoff Skerrett wrote:
          > Trying to get my first template working.
          >
          > When I output the results I get the following error;
          >
          > File "c:\python23\Lib\site-packages\Cheetah\NameMapper.py", line 193,
          > in valueForKey
          > return obj[key]
          > TypeError: list indices must be integers
          >
          >
          > The following is an example of the code I am trying to use; from
          > Cheetah.Template import Template custlist=[]
          > custlist.append({"custno":"abc","coname":"the Bigg
          > club","osamt":"$1200"}) custlist.append({"custno":"xyz","coname":"the
          > Small club","osamt":"$2200"})
          > custlist.append({"custno":"W123","coname":"Western
          > club","osamt":"$400")
          >
          > t = """<html><body><table>
          > #for $ecust in $custlist
          > <tr><td>$ecust.coname</td><td>$ecust.osamt</td></tr>
          > #end for
          > </table></body></html>"""
          >
          > tmpl = Template(t,searchList[custlist])

          I assume there's an '=' before the '['.

          You're missing a level of indirection.

          tmpl = Template(t, searchList=[{'custlist': custlist}])

          I'm not sure why you're getting a TypeError rather than a NotFoundError, but
          it's a moot point.

          --
          -Mike Orr (aka. Sluggo), mso@... (iron@...)
          http://sluggo.kicks-ass.org/ Cxu vi parolas Esperante?




          -------------------------------------------------------
          SF email is sponsored by - The IT Product Guide
          Read honest & candid reviews on hundreds of IT Products from real users.
          Discover which products truly live up to the hype. Start reading now.
          http://productguide.itmanagersjournal.com/
          _______________________________________________
          Cheetahtemplate-discuss mailing list
          Cheetahtemplate-discuss@...
          https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
        Your message has been successfully submitted and would be delivered to recipients shortly.