我正在尝试使用form.validate()验证后端的字符串字段,但似乎无法正常工作。在开发服务器上执行时,我得到所有代码200,但是,浏览器显示的内容没有在form.validate()条件内显示。有人可以帮我吗。我为所有文件粘贴了下面的代码。
@bp.route('/', methods = ["GET", "POST"])
@bp.route('/base', methods = ["GET", "POST"])
def custom_file_upload():
form = PreRequisitesForm(request.form)
if request.method == "POST":
if form.validate():
project_name = request.form['project_name']
flash("Project Name Received, {}".format(project_name))
return render_template("base.html", form = form)
class PreRequisitesForm(FlaskForm):
project_name = TextField(_l("Project Name"), validators = [DataRequired(), Length(min = 1, max = 140)])
{% block content %}
<html lang="en">
<head>
<!-- important metadata-->
<meta charset="utf-8">
<!-- character encoding to use-->
<meta http-equiv="X-UA-Compatible" ontent="IE=edge">
<!--microsoft edge browser, this will force the browser to render the webpage as a microsoft edge webpage-->
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- mobile optimization; how to control the website's dimension and scaling depending on the device-->
<!-- adding bootstrap.css to this html-->
<link rel="stylesheet" href="../static/css/bootstrap/bootstrap.css">
<!-- Title -->
<title>
AutoNeurals - Dashboard
</title>
</head>
<body>
<!--* Section-->
<section id="pre-requisites">
<form action="" method="post" role="form" id="preliminaries_form">
<div class="content-box-md">
<div class="container">
<div class="row">
<!-- Project Name Text Field-->
<div class="col-md-3">
<div class="form-group preliminaries">
<label>{{ form.project_name.label }}</label><br>
<div id="project_name">
<input type="text" class="form-control" name="project_name"
placeholder="Project Name">
</div>
</div>
</div>
</div>
</div>
</div>
</form>
</section>
<!--End * Section-->
<!-- Including Bootstrap JavaScipt-->
<script src="../static/js/bootstrap/bootstrap.js"></script>
<!-- Including jQuery -->
<script src="../static/js/jquery/jquery.js"></script>
<!-- Including Project java script file -->
<script src="../static/js/script.js"></script>
<!-- Getting Flashed Messages-->
{% with messages = get_flashed_messages() %}
{% if messages %}
<ul>
{% for message in messages %}
<li>{{ message }}</li>
{% endfor %}
</ul>
{% endif %}
{% endwith %}
</body>
</html>
{% endblock %}
#jQuery Function
$("#project_name").focusout(function() {
$("#preliminaries_form").submit();
});