pyTenjin recursive function call

17 views
Skip to first unread message

Grashopa

unread,
Jul 31, 2013, 1:38:45 PM7/31/13
to kuwata-la...@googlegroups.com
The following fails to run with "NameError: name 'printComments' is not defined", but the outputted python code looks fine.

<?py
def printComments(lst, depth):
  for d in lst:
?>
      <div class="children">
      <?py printComments(d['children'], depth+1) ?>
      </div>
  <?py #endfor ?>
<?py #enddef ?>

File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Tenjin-1.1.1-py2.6.egg/tenjin.py", line 991, in render
    exec(self.bytecode, globals, locals)


Grashopa

unread,
Jul 31, 2013, 2:31:55 PM7/31/13
to kuwata-la...@googlegroups.com
I defined the function at the top of the template and duplicated its body inside the html template which allows printComments to be called since it is now fully defined above that point, but I fail on global _extend not being defined inside the def.  It looks like you can't put html inside a function??

NameError: global name '_extend' is not defined

Again I don't see anything wrong with the generated python code.

Mark

Grashopa

unread,
Jul 31, 2013, 2:40:53 PM7/31/13
to kuwata-la...@googlegroups.com
>>NameError: global name '_extend' is not defined

putting

global _extend, etc..

at the top of the def fixed all the nameerrors


Reply all
Reply to author
Forward
0 new messages