Html db.Model.all()返回一个空列表
这是我的Html db.Model.all()返回一个空列表,html,python-2.7,google-app-engine,jinja2,google-cloud-datastore,Html,Python 2.7,Google App Engine,Jinja2,Google Cloud Datastore,这是我的tips.html模板的一个片段,包含在index.html中: {% for t in tips %} <div class="col-lg-4 col-sm-6"> <form action="comment.html" method="get" class="portfolio-box"> <img src="img/portfolio/4.jpg" class="img-responsive" alt="">
tips.html
模板的一个片段,包含在index.html
中:
{% for t in tips %}
<div class="col-lg-4 col-sm-6">
<form action="comment.html" method="get" class="portfolio-box">
<img src="img/portfolio/4.jpg" class="img-responsive" alt="">
<div class="portfolio-box-caption">
<div class="portfolio-box-caption-content">
<div class="project-category text-faded">
{{ t.title }}
</div>
<div class="project-name">
{{ t.content }}
</div>
<div><br /></div>
{% if user != 'None' %}
<input type="hidden" name="tipTitle" value="{{ t.title }}">
<input type="hidden" name="tipContent" value="{{ t.content }}">
<input type="hidden" name="hparam" value="tips">
<div><button class="btn btn-default btn-l wow tada">Explore</button></div>
{% endif %}
</div>
</div>
</form>
</div>
{% endfor %}
我的处理程序
class MainPage(BaseHandler):
def get(self):
template = JINJA_ENVIRONMENT.get_template('index.html')
query = Tip.all()
context = {
'title' :'OutgoingIndex - ' + currentUser.username,
'user' : currentUser.username,
'tips' : query
}
self.response.write(template.render(context))
看起来你是以下行为的受害者: GAE数据存储环境中的一致性,用非常简单、非技术性的术语来说,就是“数据最新副本的可用性”。也许更直观(但明显不正确)的定义是“写入和读取之间没有延迟”。强一致性意味着最小或无延迟,即写入的数据可立即用于后续读取。最终一致性意味着存在相当大的延迟,即写入的数据在传播并存储到多个数据中心后,将“最终”可用于读取 因此,发生的情况是,您将在写操作完成之后,但在它传播之前返回提示列表,因此此时数据不在索引中。如果在重定向或刷新之前等待几秒钟,数据就会在那里
这很正常,你会习惯的。但是,如果您使用的是。如果您对这一主题不熟悉,这篇文章可能会很有趣:。您能向我们展示models.py和views.py吗?@JoãoVilaça当然,我编辑的postmodels似乎是正确的,您也能添加view.py吗?要想知道这是否是一个上下文问题,我的视图基本上都是html文件,我没有view.py@JoãoVilaça你是说处理程序吗?嗯,你总是有一个url.py、views.py和models.py,html和models.py是正确的,所以问题是“tips”传递时没有任何值,它是空的,所以它可能是上下文问题,您可以在views.py文件中处理它
class MainPage(BaseHandler):
def get(self):
template = JINJA_ENVIRONMENT.get_template('index.html')
query = Tip.all()
context = {
'title' :'OutgoingIndex - ' + currentUser.username,
'user' : currentUser.username,
'tips' : query
}
self.response.write(template.render(context))