我找到了一种在内部获取变量的“更好”的解决方案,虽然不是最好的方法,但是它可以工作。
你将自定义过滤器安装到Django中,该过滤器将dict的键作为参数
为了使其能够在Google App Engine中工作,你需要向主目录中添加一个文件,我称其为django_hack.py,其中包含以下这段代码
from google.appengine.ext import webappregister = webapp.template.create_template_register()def hash(h,key): if key in h: return h[key] else: return Noneregister.filter(hash)
现在我们有了这个文件,我们需要做的就是告诉应用程序引擎使用它…我们通过在主文件中添加这一行来做到这一点
webapp.template.register_template_library('django_hack')并在模板视图中添加此模板,而不是通常的代码
{{ user|hash:item }}


