Flask WTF是否未发布?

时间:2019-04-29 13:55:51

标签: flask flask-wtforms wtforms

我有一个表格,为了测试,我只想在提交表格后打印出字典。但是,页面只是刷新,并且在日志中显示我正在执行post方法。

我在班上的Wtf如下:

class BpaForm(FlaskForm):
    idv_id = StringField('IDV Id', validators=[DataRequired()])
    duns = StringField('Dun Number', validators=[DataRequired()])
    name = StringField('Name', validators=[DataRequired()])
    multi_or_single = SelectField('Multiple or Single',
                                  choices=MultiOrSingle.choices())
    signed_date = DateField('Date Signed', format='%Y-%m-%d')
    tcv = FloatField('TCV')
    submit = SubmitField()

路线如下:

@bpa_bp.route('/bpa-entry', methods=['POST', 'GET'])
def get_bpa_info():
    form = BpaForm()
    existing = [i.name for i in BPA.query.with_entities(BPA.name).distinct().all()]
    print(existing)
    if form.validate_on_submit():
        test = {}
        test['idv_id'] = form.idv_id.data
        test['duns'] = form.duns.data
        test['name'] = form.name.data
        test['multi_or_single'] = form.multi_or_single.data
        test['signed_date'] = form.signed_date.data
        test['tcv'] = form.tcv.data
        print(test)
        return redirect('get_bpa_info')
    return render_template('bpa-form.html',
                           form=form,
                           existing=existing)

我的网络表单如下:

{% block content %}

<div class="container">
  <div class="row">
    <div class="col-sm-6">
      <form action="" method="POST">
        {{ form.csrf_token }}
        <div class="form-group">
          {{ form.idv_id(class="form-control", placeholder="IDV ID") }}
        </div>
        <div class="form-group">
          {{ form.duns(class="form-control", placeholder="Duns Number") }}
        </div>
        <div class="form-group">
          {{ form.name(class="form-control", placeholder="Name, e.g. FDA IT Helpdesk BPA", list="id_datalist") }}
          <datalist id="id_datalist">
            {% for bpa in existing %}
              <option value={{ bpa }}>
            {% endfor %}
          </datalist>
        </div>
        <div class="form-group">
          {{ form.tcv(class="form-control", placeholder="Total Contract Value") }}
        </div>
        <div class="form-group">
          <div class="col-md-4 mb-3">
            {{ form.multi_or_single(class="form-control") }}
          </div>
        </div>
        <div class="form-group">
          {{ form.signed_date(class='datepicker') }}
        </div>
        <p>{{ form.submit(class="btn btn-primary") }}</p>
      </form>
    </div>
  </div>
</div>

{% endblock %}

我的笨拙的样子:

提交之前:

2019-04-29 09:45:37,309 INFO sqlalchemy.engine.base.Engine SELECT DISTINCT bpa.name AS bpa_name
FROM bpa
2019-04-29 09:45:37,309 INFO sqlalchemy.engine.base.Engine {}
['testname', 'name']
2019-04-29 09:45:37,338 INFO sqlalchemy.engine.base.Engine ROLLBACK
127.0.0.1 - - [29/Apr/2019 09:45:37] "GET /bpa-entry HTTP/1.1" 200 -

提交后:

2019-04-29 09:47:28,795 INFO sqlalchemy.engine.base.Engine BEGIN (implicit)
2019-04-29 09:47:28,796 INFO sqlalchemy.engine.base.Engine SELECT DISTINCT bpa.name AS bpa_name
FROM bpa
2019-04-29 09:47:28,796 INFO sqlalchemy.engine.base.Engine {}
['testname', 'name']
2019-04-29 09:47:28,848 INFO sqlalchemy.engine.base.Engine ROLLBACK
127.0.0.1 - - [29/Apr/2019 09:47:28] "POST /bpa-entry HTTP/1.1" 200 -
127.0.0.1 - - [29/Apr/2019 09:47:28] "GET /static/css/style.css?q=1551043377 HTTP/1.1" 200 -

我不确定为什么不打印test词典就刷新页面吗?

0 个答案:

没有答案