我得到:“Lantern”类型的参数在模板引擎文件之一(Cheetah)中不可迭代。你可以猜到obj是一个 Lantern(见下文)。
NameWrapper.py:
if hasattr(obj, 'has_key') and key in obj:
这是我的模型的简化版本。没什么花哨的,没有额外的方法只是属性声明。
模型.py:
from google.appengine.ext import db
class Product(db.Model):
name = db.StringProperty(required=True)
class Lantern(Product):
height = db.IntegerProperty()
- 我该如何解决这个问题?
- 是否正确,AppEngine 模型具有函数has_key但不可迭代?
解决方案(编辑):
我已经更换了线路。
if hasattr(obj, 'has_key') and isinstance(obj, collections.Iterable) and key in obj: