gpt4 book ai didi

python - 如何查询 Google App Engine 数据存储并将结果传递到新页面?

转载 作者:太空宇宙 更新时间:2023-11-04 06:36:57 25 4
gpt4 key购买 nike

鉴于以下来自 Google App Engine 的 Python 代码摘录演示了我的工作数据存储模型,我如何查询我的模型实体并在名为 showall.htmlshowlist 的新页面上显示结果.html?

from google.appengine.ext import db
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app

class PersonInfo(db.Model):
firstname = db.StringProperty()

lastname = db.StringProperty()

book = db.StringProperty()

email = db.StringProperty()

phone = db.StringProperty()

os = db.StringProperty()

class MainPage(webapp.RequestHandler):
def get(self):

[...提交表单处理程序...]

class Register(webapp.RequestHandler):
def post(self):
personinfo = PersonInfo()
firstname = self.request.get('firstname')
lastname = self.request.get('lastname')
phone = self.request.get('phone')
book = self.request.get('book')
email = self.request.get('email')
os = self.request.get('os')

#This puts stuff in database
personinfo.firstname=firstname
personinfo.lastname=lastname
personinfo.phone=phone
personinfo.book=book
personinfo.email=email
personinfo.os=os
personinfo.put()


self.response.out.write("""
<ul>
<li><a href = "showall.html">Show All People Registered</a></li>
<li><a href = "showlist.html">Show People Inside This List</a></li>
</ul>""")

application = webapp.WSGIApplication(
[('/', MainPage),
('/sign', Register),
],debug=True)

def main():
run_wsgi_app(application)


if __name__ == "__main__":
main()

最佳答案

来自 Queries and Indexes :

# The Query interface constructs a query using instance methods.
q = Person.all()
q.filter("last_name =", "Smith")
q.filter("height <", 72)
q.order("-height")

# The GqlQuery interface constructs a query using a GQL query string.
q = db.GqlQuery("SELECT * FROM Person " +
"WHERE last_name = :1 AND height < :2 " +
"ORDER BY height DESC",
"Smith", 72)

# The query is not executed until results are accessed.
results = q.fetch(5)
for p in results:
print "%s %s, %d inches tall" % (p.first_name, p.last_name, p.height)

关于python - 如何查询 Google App Engine 数据存储并将结果传递到新页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9525029/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com