gpt4 book ai didi

python - Google App Engine 数据库未显示

转载 作者:行者123 更新时间:2023-11-28 21:57:48 24 4
gpt4 key购买 nike

我在我的应用程序中创建了一个实体“FlipKart”,并在我运行查询的地方使用了一个处理程序,以便我可以在我的 HTML 表单中显示给定的条目。我有 Jinja2 模板来组织我的 html 文件。

这是实体的代码:

class FlipKart(db.Model):
name = db.StringProperty()
quantity = db.IntegerProperty()
total = db.IntegerProperty()

这是我处理和运行查询的处理程序:

class WebeHandler(Handler):         
def get(self):
self.render("we.html")
def post(self):
b_name = self.request.get("bkname")
b_quantity = self.request.get("qnty")
b_total = self.request.get("tot")

if(b_name and b_quantity and b_total):
a = FlipKart(BookName = b_name, Quantity = b_quantity, GrandTotal = b_total)
a.put()
self.final()
def final(self):
flips = db.GqlQuery("SELECT * FROM FlipKart")
self.render("we.html", flips = flips)

这是我的 html 文件:

<html>
<head>
<title>Web Engineering</title>
<style type = "text/css">

</style>
</head>

<body>
<form method = "post">
Book Name<input type = "text" name = "bkname">
<br>
Quantity<input type = "text" name = "qnty">
<br>
Total Prize<input type = "number" name = "tot">
<br>
<input type = "submit">
<br><br><br>
<hr>

{%
for flip in flips
%}
<div>You have ordered a {{flip.name}}</div>
{%endfor%}
</form>
</body>

但是,当我运行这个应用程序时,我在浏览器中的表单后得到以下文本:

You have ordered a None
You have ordered a None
You have ordered a None
You have ordered a None
You have ordered a None
You have ordered a None
You have ordered a None
You have ordered a None
You have ordered a None
You have ordered a None
You have ordered a None
You have ordered a None
You have ordered a None
You have ordered a None
You have ordered a None
You have ordered a None
You have ordered a None
You have ordered a None

似乎是什么问题?

最佳答案

你的查询没有问题,可以看到循环重复了。你的问题是你创建实体的代码

a = FlipKart(BookName = b_name, Quantity = b_quantity, GrandTotal = b_total)

你的模型定义为

class FlipKart(db.Model):
name = db.StringProperty()
quantity = db.IntegerProperty()
total = db.IntegerProperty()

您实际上并未在实体中存储任何值。这是非常基本的 Python。

类构造函数调用应该是

a = FlipKart(name = b_name, quantity = b_quantity, total = b_total)

您需要按照其他答案进行 int 转换,您没有收到赋值错误的唯一原因是您从未将值赋给属性。

另请注意,由于最终一致性,您的查询可能不会显示最近添加的实体,(我会让您对此进行一些阅读)

关于python - Google App Engine 数据库未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19336732/

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