Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在html模板中打印appengine模型实体id_Python_Google App Engine_Jinja2_Webapp2 - Fatal编程技术网

Python 在html模板中打印appengine模型实体id

Python 在html模板中打印appengine模型实体id,python,google-app-engine,jinja2,webapp2,Python,Google App Engine,Jinja2,Webapp2,以下是我拥有的简单数据库模型: class Notes(db.Model): text = db.StringProperty(multiline=True) date = db.DateTimeProperty(auto_now_add=True) 现在在url处理程序中,我将所有注释发送到模板,如下所示: class MainPage(webapp2.RequestHandler): def get(self): notes = Notes.all() self

以下是我拥有的简单数据库模型:

class Notes(db.Model):
  text = db.StringProperty(multiline=True)
  date = db.DateTimeProperty(auto_now_add=True)
现在在url处理程序中,我将所有注释发送到模板,如下所示:

class MainPage(webapp2.RequestHandler):
  def get(self):
    notes = Notes.all()
    self.render_template("index.html", {'notes':notes})
在使用模板引擎的模板中,我希望打印每个注释的
id
,以便嵌入编辑链接,有点像这样:

{% for note in notes %}
<p>  
 {{ note.text }} <br>
 {{ note.date }} <br>
 (<a href ="edit/{{note.key.id}}">edit </a>)
{% endfor %}
{%用于notes%中的注释]

{{note.text}}
{{note.date}}
() {%endfor%}
但问题是,我没有看到任何打印的内容,而不是
note.key.id
根据docs over
key
类表示数据库实体的唯一键,它有一个方法
id
,它是一个数值。对于笔记集合中的单个笔记,我需要笔记的
id

如果我使用django模板引擎,我会打印值
{{notes.key.id}
,但是使用
jinja2
我看不到它


我该怎么做呢?

我们将
href
行替换为以下内容:

(<a href ="edit/{{note.key().id()}}">edit </a>)
()

这就足够了。

我刚刚测试了它,在我的情况下,我必须按照如下方式调整您的解决方案:
{{job.key.id()}
(key,而不是key()),使用python 2.7、flask、jinjia2、ndb。。。