首页 > 解决方案 > 表单在提交发布请求时被清除

问题描述

我想防止我的表单在烧瓶中的发布请求中被清除。这是我的代码:

预测器.html

<!doctype html>
<html>
<head>
<meta charset="UTF-8">

  <meta name="viewport" content="width=device-width, initial-scale=1">

  <link rel="stylesheet" type="text/css" href="static/vendor/bootstrap/css/bootstrap.min.css">
<!--===============================================================================================-->
  <link rel="stylesheet" type="text/css" href="static/fonts/font-awesome-4.7.0/css/font-awesome.min.css">
<!--===============================================================================================-->
  <link rel="stylesheet" type="text/css" href="static/vendor/animate/animate.css">
<!--===============================================================================================-->
  <link rel="stylesheet" type="text/css" href="static/vendor/select2/select2.min.css">
<!--===============================================================================================-->
  <link rel="stylesheet" type="text/css" href="static/vendor/perfect-scrollbar/perfect-scrollbar.css">
<!--===============================================================================================-->
  <link rel="stylesheet" type="text/css" href="static/css/util.css">
  <link rel="stylesheet" type="text/css" href="static/css/main.css">


</head>
<body>
<form method="POST" id="Formid">
<div class="form-group" onsubmit="return false">
<input type="text" class="form-control input-sm" id="input" name="data_input" style="width:100%" maxlength="500"placeholder="Sepal length">
<input type="text" class="form-control input-sm" id="input" name="data_input" style="width:100%" maxlength="500"placeholder="Sepal Width">
<input type="text" class="form-control input-sm" id="input" name="data_input" style="width:100%" maxlength="500"placeholder="Petal length">
<input type="text" class="form-control input-sm" id="input" name="data_input" style="width:100%" maxlength="500"placeholder="Petal Width">
<button type="submit" class="btn btn-success" value="Submit" method="get"><i class="fa fa-search" aria-hidden="true"></i></button>
{{predictions}}
</div>

</form>

</body>
</html>

这是提交表单的示例,我得到输出,但表单值被清除

标签: javascriptpythonhtml

解决方案


如果我猜对了,您需要保留表单中其他字段的值,如果表单由于一个或多个无效input而无法处理。input

在发布请求之后,将有效input字段的值存储在变量中并将它们传递到标签中的value属性中,input以便在下次重新加载时预填充表单的输入。

像这样<input type="text" value="{{ some_variable }}" />

您最初可以将这些变量设置为空字符串,以便用户首次输入。


推荐阅读