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

[Cheetahtemplate-discuss] Jython or Cheetah giving me a NameMapper error?

Expand Messages
  • Mike Nowak
    Hi there. I am new to Cheetah but I am trying to evaluate it as a templating engine for sending tailored email within a Java program (Velocity is another
    Message 1 of 1 , Jul 16 3:15 PM
      Hi there. I am new to Cheetah but I am trying to evaluate it as a
      templating engine for sending tailored email within a Java program
      (Velocity is another option) but I've run into a snag when using it
      under Jython (I have not tried this directly under Python).

      I am using Cheetah 0.9.15 and Jython 2.1.
      I've set up a simple template and a dictionary but I keep getting a
      NameMapper error:

      // interpreter.exec("templateDef = \"" + templateField.string() + "\"");
      // interpreter.exec("templateDict = {\"firstName\": \"Mike\", \"age\":
      38}");
      // interpreter.exec("templateObj = Template(templateDef,
      searchList=[templateDict])");

      // interpreter.exec("print templateDef");
      $firstName

      // interpreter.exec("print templateObj.searchList()");
      [{}, {'age': 38, 'firstName': 'Mike'}, <Cheetah.Template.Template
      instance at 4371936>]

      // interpreter.exec("print templateObj.respond()");
      2003-07-16 18:06:33.556 CheetahSample[3181] org/python/core/PyException
      Stack Trace:
      Traceback (innermost last):
      File "<string>", line 1, in ?
      File "<string>", line 28, in respond
      File
      "/Users/mnowak/Documents/HMRL/MENU/CheetahSample/build/
      CheetahSample.app/Contents/Resources/Java/Lib/Cheetah/NameMapper.py",
      line 254, in valueFromSearchList
      NotFound: firstName

      I thought maybe my dictionary wasn't right so I tried this:

      // interpreter.exec("templateDef = \"" + templateField.string() + "\"");
      // interpreter.exec("templateDict = {\"firstName\": \"Mike\", \"age\":
      38}");
      // interpreter.exec("templateObj = Template(templateDef,
      searchList=[templateDict])");

      // interpreter.exec("print templateDict");
      {'age': 38, 'firstName': 'Mike'}

      interpreter.exec("print templateDict.has_key(\"firstName\")");
      1

      interpreter.exec("print hasattr(templateDict, \"firstName\")");
      0

      interpreter.exec("print setattr(templateDict, \"firstName\",
      \"Mike\")");
      2003-07-16 18:08:41.108 CheetahSample[3206] org/python/core/PyException
      Stack Trace:
      Traceback (innermost last):
      File "<string>", line 1, in ?
      TypeError: readonly class or attribute: firstName

      I am at a loss to know if I have not set up my dictionary correctly or
      if this is some kind of Jython incompatibility.

      I would really appreciate any help!

      --
      Mike Nowak
      Health Media Research Laboratory, The University of Michigan
      http://healthmedia.umich.edu/



      -------------------------------------------------------
      This SF.net email is sponsored by: VM Ware
      With VMware you can run multiple operating systems on a single machine.
      WITHOUT REBOOTING! Mix Linux / Windows / Novell virtual machines at the
      same time. Free trial click here: http://www.vmware.com/wl/offer/345/0
      _______________________________________________
      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.