如何制作带有三个按钮而不是下拉菜单的烧瓶SelectField表单

时间:2019-11-23 19:34:25

标签: python html twitter-bootstrap flask flask-wtforms

我试图用三个单独的按钮(而不是一个下拉菜单)填充一个烧瓶SelectForm,但是我不确定如何做到。如果有一种方法可以使每个按钮使用不同的颜色,但使用相同的形式,我也将不胜感激。我的代码在下面。

forms.py

class NewForm(FlaskForm):

    category = SelectField('Category', choices=[('1', 'Red'), ('2', 'Blue'), ('3', 'Yellow')])

    submit = SubmitField('Create')

forms.html

             <div class = "form-group">
                {{ form.category.label(class = "form-control-label") }}
                {% if form.category.errors %}
                    {{ form.category(class = "form-control form-control-lg is-invalid") }}
                    <div class = "invalid-feedback">
                        {% for error in form.category.errors %}
                            <span>{{ error }}</span>
                        {% endfor %}
                    </div>
                {% else %}
                    {{ form.category(class = "btn btn-outline-dark") }}
                {% endif %}
            </div>

routes.py


@app.route("/form/ methods = ['GET', 'POST'])
def form(client_id):

    form = NewForm()

    if form.validate_on_submit():

        object = Object(category=form.category.data)

        db.session.add(object)
        db.session.commit()

        return redirect(url_for('home'))


    return render_template('form.html', form=form)

This is how it currently looks

I want it to look like this(I used "INSPECT")

0 个答案:

没有答案