【发布时间】:2020-09-02 21:02:38
【问题描述】:
背景:
我创建了一个非常简单的前端,用户可以在其中输入字符串。输入并单击“检查”按钮后,我想将此字符串作为 JSON 传递给 python 字符串,它将在其中进行 SQL 查找。根据 SQL 外观,python 脚本应该传递一个布尔值,该值应该改变 ?到 ✔ 或 ✘。
问题:
如何将“检查”按钮作为 JSON 按 JSON 传递给 Python 脚本,然后将布尔值从 Python 传递到 HTML 以将 ? 更改为 ✔ 或 ✘?
研究:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {font-family: Arial, Helvetica, sans-serif;}
* {box-sizing: border-box;}
input[type=text], select, textarea {
width: 100%;
padding: 12px;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
margin-top: 6px;
margin-bottom: 16px;
resize: vertical;
}
input[type=submit] {
background-color: #4CAF50;
color: white;
padding: 12px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
}
input[type=submit]:hover {
background-color: #45a049;
}
.container {
border-radius: 5px;
background-color: #f2f2f2;
padding: 20px;
}
h3 {text-align: center;}
.center {
display: flex;
justify-content: center;
align-items: center;
}
</style>
</style>
</head>
<body>
<h3>My Request</h3>
<div class="container">
<form action="/action_page.php">
<label for="account_name">? Account Name:</label>
<input type="text" id="fname" name="firstname" placeholder="Account Name..">
<input type="submit" value="Check Account"><br><br>
<label for="contact_name">? Contact Name:</label>
<input type="text" id="lname" name="lastname" placeholder="Contact Name..">
<input type="submit" value="Check Contact"><br><br>
<label for="reseller">? Reseller:</label>
<input type="text" id="lname" name="lastname" placeholder="Reseller..">
<input type="submit" value="Check Reseller"><br><br>
<label for="issue_date">? Issue Date:</label><br>
<input type="date" id="start" name="trip-start" value="" min="2018-01-01" max="2100-12-31">
<br>
<div class="center">
<input type="submit" value="VERIFY ALL">
</div>
</form>
</div>
</body>
</html>
【问题讨论】:
-
你需要一个 HTML 表单
-
@user1558604 我很快把它改成了一个表格,不像以前的那么漂亮,但是一个表格...
-
你需要使用一些 AJAX。如果您使用 jQuery,请查看 jQuery.Post。您将要检查的值发布到 Flask/Python 端点,然后使用回调方法根据响应更新复选框标记。
-
您使用的是 Flask 还是其他类型的端点?
-
@ngShravil.py 什么都没有 - 我对任何事情都持开放态度 - 我不知道从哪里开始.....