微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Flask模板中的多个表单可以一次提交

如何解决Flask模板中的多个表单可以一次提交

enter image description here

背景:

操作:将wrongvalue放入删除DP表单,然后按Delete DP

预期:仅在DP的用户名文本框中显示错误

实际:在其他形式的其他文本框中也显示错误

Forms.py ::

class UpdateAccountForm(FlaskForm):
    # Statements ...

class DeletedisplayPic(FlaskForm):
    # Statements ...

Routes.py ::

    if deletedp_form.validate_on_submit():
        #Statements...

    if update_form.validate_on_submit():
        #Statements...

account.html(根据Navneetha Krishnan的要求)::

{% extends "layout.html" %}
{% block content %}
  <div class="content-section pt-4 mt-3">

<!--UPDATE ACCOUNT-->
    <form method="POST" action="" enctype="multipart/form-data">
      {{ update_form.hidden_tag() }}

<!--USERNAME-->
      <fieldset class="form-group">
        <legend class="border-bottom mb-4">Account Info</legend>
        <div class="form-group">
          {{ update_form.username.label(class="form-control-label") }}
          {% if update_form.username.errors %}
            {{ update_form.username(class = "form-control form-control-lg is-invalid") }}
            <div class="invalid-Feedback">
              {% for error in update_form.username.errors %}
                <span>{{ error }}</span>
              {% endfor %}
            </div>
          {% else %}
            {{ update_form.username(class="form-control form-control-lg") }}
          {% endif %}
        </div>

<!--EMAIL-->
        <div class="form-group">
          {{ update_form.email.label(class="form-control-label") }}
          {% if update_form.email.errors %}
            {{ update_form.email(class = "form-control form-control-lg is-invalid") }}
            <div class="invalid-Feedback">
              {% for error in update_form.email.errors %}
                <span>{{ error }}</span>
              {% endfor %}
            </div>
          {% else %}
            {{ update_form.email(class="form-control form-control-lg") }}
          {% endif %}
        </div>

<!--disPLAY PIC-->
        <div class="form-group">
          {{ update_form.dispic.label() }}
          {{ update_form.dispic(class='form-control-file') }}
          {% if update_form.dispic.errors %}
            {% for error in update_form.dispic.errors %}
              <span class="text-danger">{{ error }}</span><br>
            {% endfor %}
          {% endif %}
        </div>
      </fieldset>
      <div class="form-group">
        {{ update_form.update_submit(class = "btn btn-outline-info") }}
      </div>
    </form>

<!--DELETE DP-->
    <form method="POST" action="" >
      {{ deletedp_form.hidden_tag() }}
      <fieldset class="form-group">
        <legend class="border-bottom my-4 ">Delete display Picture</legend>

<!--USERNAME-->
        <div class="form-group">
          {{ deletedp_form.deletedp_username.label(class="form-control-label") }}
          {% if deletedp_form.deletedp_username.errors %}
            {{ deletedp_form.deletedp_username(class = "form-control form-control-lg is-invalid") }}
            <div class="invalid-Feedback">
              {% for delerror in deletedp_form.deletedp_username.errors %}
                <span>{{ delerror }}</span>
              {% endfor %}
            </div>
          {% else %}
            {{ deletedp_form.deletedp_username(class="form-control form-control-lg") }}
          {% endif %}
        </div>
      </fieldset>

<!--SUBMIT-->
      <div class="form-group">
        {{ deletedp_form.deletedp_submit(class = "btn btn-outline-danger") }}
      </div>
    </form>

  </div>
{% endblock content %}

如果需要,我一定会添加更多信息。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。