python - 如何在 python 的同一页面上显示显示的 db.query 搜索结果
问题描述
我有一个 html 页面(searchCustomer.html),它有一个输入字段,我们在其中输入要在数据库中搜索的字符串,在我们单击搜索按钮后成功获取记录并以 html 显示。我想显示从 html 中单击的记录的详细信息,当在同一页面(searchCustomer.html)中单击第一列(即 href)时
<form action="/getsearchresults" method="post">
<!-- <form action="/getsearchresults" method= methods=['GET', 'POST'] > -->
<Text text="Customer Name" id="text0"/>
<Input width="200px" name="custName" required placeholder="Please enter the customer name"/>
<button type="submit">Search Customer</button>
<button id="#btnID">TEst Customer</button>
</form>
<table border="1">
<tr><td><strong>Customer Id</strong></td><td><strong>Name</strong></td></tr>
{% for name1 in customers %}
<tr><td><a href="/DispCustomerInfo?query={{ name1.name }}">{{name1.id}}</a></td><td>{{name1.name}}
</td></tr>
{% endfor %}
</table>
单击href,我想在同一页面中显示该记录的详细信息
解决方案
这是一个可能的解决方案
from flask import request, jsonify
@app.route('/DispCustomerInfo')
def get_customer_info():
name = request.args.get('query', False)
customer = {}
if name:
#1 Query database
#2 Assign result to customer
return jsonify(customer)
在前端Ajax
用于获取客户数据。
<td><a class="customername" href="#" data-name="{{ name1.name }}">{{name1.id}}</a></td>
$( document ).ready(function() {
$(".customername").on('click', function(){
var name = $(this).data('name');
$.get("/getReport", {'query': name}).done(function (data) {
// Use jquery to append customer data to a DOM element.
});
});
});
推荐阅读
- javascript - 我不明白为什么我的消息没有发送给每个决定收到通知的用户。它只发送给一个
- visual-studio-code - 连接 FTP 帐户时出现 FTP 关闭消息
- list - 在颤动中从列表中添加和删除对象
- java - 为什么运行时绑定不会在编译时发生?
- jquery - 获取选择数据列表项的数据属性
- jenkins - Jenkins - 如果提交消息不包含字符串,则跳过构建
- arcgis - 如何使用 ArcPy 在地理数据库中编辑 GIS shapefile?
- ios - 处理 Podfile 的安装后挂钩时出错。无法在 iOS 模拟器上运行颤振项目得到 pod 错误
- python - discord.py bot“命令的检查功能失败”
- svg - 将 png 格式的阴影转换为 svg