html 基本烧瓶WTF表格

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了html 基本烧瓶WTF表格相关的知识,希望对你有一定的参考价值。

from flask import Flask, render_template
from flask_wtf import FlaskForm
from wtforms import StringField,SubmitField

app = Flask(__name__)
# Configure a secret SECRET_KEY
# Has to be here, otherwise the app will not started
app.config['SECRET_KEY'] = 'mysecretkey'

# Now create a WTForm Class
# Lots of fields available:
# http://wtforms.readthedocs.io/en/stable/fields.html
class InfoForm(FlaskForm):
    '''
    This general class gets a lot of form about puppies.
    Mainly a way to go through many of the WTForms Fields.
    '''
    breed = StringField('What breed are you?')
    submit = SubmitField('Submit')

@app.route('/', methods=['GET', 'POST'])
def index():
    # Set the breed to a boolean False.
    # So we can use it in an if statement in the html.
    breed = False
    # Create instance of the form.
    form = InfoForm()
    # If the form is valid on submission (we'll talk about validation next)
    if form.validate_on_submit():
        # Grab the data from the breed on the form.
        breed = form.breed.data
        # Reset the form's breed data to be False
        form.breed.data = ''
    return render_template('00-home.html', form=form, breed=breed)


if __name__ == '__main__':
    app.run(debug=True)
<p>
{% if breed %}
  The breed you entered is {{breed}}.
  You can update it in the form below:
{% else %}
  Please enter your breed in the form below:
{% endif %}
</p>

<form method="POST">
    {# This hidden_tag is a CSRF security feature. #}
    {{ form.hidden_tag() }}
    {{ form.breed.label }} {{ form.breed(class='some-css-class') }}
    {{ form.submit() }}
</form>

以上是关于html 基本烧瓶WTF表格的主要内容,如果未能解决你的问题,请参考以下文章

烧瓶WTF到烧瓶邮件附件?

我似乎无法让我的烧瓶应用程序显示我的 Form-flask_wtf

我想在底部的索引页面本身的烧瓶中处理联系表格[重复]

尝试仅使用 html 按钮将数据传递给烧瓶应用程序

重新学习python系列? WTF?

使用类创建的数据无法通过烧瓶应用程序显示到 html 中