【问题标题】:how to Reference some model in a db.ListProperty on google-app-engine如何在 google-app-engine 上的 db.ListProperty 中引用某些模型
【发布时间】:2010-07-17 19:37:55
【问题描述】:

这是我的模型:

class Geo(db.Model):
    entry = db.ListProperty(db.Key)

geo=Geo()
geo.entry.append(otherModel.key())

html 是:

{% for i in geo.entry %}
        <p><a href="{{ i.link }}">{{ i.title }}</a></p>
{% endfor%}

但它什么也没显示,

我认为也许应该:

class Geo(db.Model):
    entry = db.ListProperty(db.Model)
geo=Geo()
geo.entry.append(otherModel)

但它显示:

ValueError: Item type Model is not acceptable

那么,如何让 html 显示正确的东西。

谢谢

【问题讨论】:

    标签: python google-app-engine listproperty


    【解决方案1】:

    您不能使用该模板(或类似模板)直接显示模型,但您可以轻松地通过在键列表上调用 db.get 来准备包含模型列表的上下文 - 例如,使用 @ 987654322@ 在上下文字典的开头,for i in entries 在模板中。

    【讨论】:

      猜你喜欢
      • 2013-12-18
      • 1970-01-01
      • 2015-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多