我正在使用cherrypy
并mako
与 Python 一起创建一个网站。
在我的一个 HTML 文件中,我有以下 Lambda 函数:
${reduce(lambda list, cur : '<li>' + someFunction(cur) + '</li>' +
list, object.listing, '')}
object.listing
带有字符串的列表在哪里。
执行导致上述错误:“未定义”对象不可调用。如果我删除someFunction()
. 所以我认为它与cur
存在None
或有关Undefined
,但我不知道如何防止这种情况。
我什至不太确定 reduce 函数是如何工作的。
根据要求,整个堆栈跟踪:
[26/Dec/2012:13:15:22] HTTP
Request Headers:
REFERER: http://localhost:8080/list
HOST: localhost:8080
CONNECTION: keep-alive
Remote-Addr: 127.0.0.1
ACCEPT: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
USER-AGENT: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:17.0) Gecko/20100101 Firefox/17.0
COOKIE: session_id=960e569568ded77610f11c48bec0a806f5a4501b
ACCEPT-LANGUAGE: en-US,en;q=0.5
DNT: 1
ACCEPT-ENCODING: gzip, deflate
[26/Dec/2012:13:15:22] HTTP Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/CherryPy-3.2.2-py2.7.egg/cherrypy/_cprequest.py", line 656, in respond
response.body = self.handler()
File "/Library/Python/2.7/site-packages/CherryPy-3.2.2-py2.7.egg/cherrypy/lib/encoding.py", line 188, in __call__
self.body = self.oldhandler(*args, **kwargs)
File "/Library/Python/2.7/site-packages/CherryPy-3.2.2-py2.7.egg/cherrypy/_cpdispatch.py", line 34, in __call__
return self.callable(*self.args, **self.kwargs)
File "/Volumes/Ritalin/Projects/splitpot/controller/Splitpot.py", line 54, in event
return tmpl.render(object=doSomething())
File "/Library/Python/2.7/site-packages/mako/template.py", line 412, in render
return runtime._render(self, self.callable_, args, data)
File "/Library/Python/2.7/site-packages/mako/runtime.py", line 766, in _render
**_kwargs_for_callable(callable_, data))
File "/Library/Python/2.7/site-packages/mako/runtime.py", line 798, in _render_context
_exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
File "/Library/Python/2.7/site-packages/mako/runtime.py", line 824, in _exec_template
callable_(context, *args, **kwargs)
File "base_html", line 31, in render_body
File "someFile_html", line 58, in render_body
File "someFile_html", line 58, in <lambda>
TypeError: 'Undefined' object is not callable