【发布时间】:2023-03-15 01:40:01
【问题描述】:
您好,我是烧瓶和 html 的新手。 我有一个数据库,其中包含具有以下结构的文档集合(代表道路路线):
我希望能够通过如下结构的 html 页面查询我的 mongodb:
我在第一个字段中输入我的位置的位置(Lat1,Long1)在我的目的地的第二个字段插入(Lat2,Long2),如果它存在于数据库中,则通过搜索按钮将其打印在页面下方它会告诉我“路线不存在”。
我在其中创建按钮的简单而琐碎的 index.html 如下:
<body>
<h1>Choose your route:</h1>
<form action="/list" method="get" autocomplete="on">
<td><input type="text" name="key" placeholder="Your Position" size="20" /></td>
<td><input type="text" name="key" placeholder="Search Destination" size="20" /></td>
<td><button type="submit">Search</button></td>
<button type="Reset" value="Reset">Reset</button>
</form>
</body>
而带有flash的python代码如下:
@app.route("/list")
def lists ():
#Display the all Task
return render_template('index.html',h=heading)
@app.route("/search", methods=['GET'])
def search():
#Searching a Task with various references
Lat1=request.values.get("Lat1")
Long1=request.values.get("Long1")
Lat2=request.values.get("Lat2")
Long=request.values.get("Long2")
refer=request.values.get("refer")
#I make the comparison to understand if the route is present in the
database.
if(Lat1 == "Lat1" and Long1 == "Long1" and Lat2 == "Lat2" and Long2 ==
"Long2"):
test_l = tests.find({Lat1:ObjectId(Lat1)})
test_l = tests.find({Long1:ObjectId(Long1)})
test_l = tests.find({Lat2:ObjectId(Lat2)})
test_l = tests.find({Long2:ObjectId(Long2)})
else:
print("Route not present")
return
render_template('searchlist.html',tests=test_l,t=title,h=heading)
searchlist.html 页面我不知道如何构建它。 所以我的问题是创建 searchlist.html 页面并更改烧瓶中的 python 代码以便能够搜索。 非常感谢。
【问题讨论】: