简体   繁体   中英

Flask-Bootstrap | WTForms support | Position

How can I position "101010" next to the first label, blue position, using wtf.quick_form()?

enter image description here enter image description here

**expectation: ** enter image description here

I have done: I changed the position of {{ 101010 }} but the value is not on the first line

You can change the label text at runtime.

@app.route("/")
def hello_world():
    _form = RateMovieForm()

    # Assign your label text at runtime
    _value = "101010"
    _form.rating.label.text = f"Your rating out of 10 e.g. {_value}"

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

Example code showing html output of label and input elements:

from wtforms.fields import FloatField
from wtforms.form import Form


class TestForm(Form):
    rating = FloatField(label="Your rating out of 10 e.g.")


def test_form():

    _form = TestForm()

    _label = _form.rating.label()  # get the generated label html
    _input = _form.rating()  # get the generated input html
    print(_label)
    print(_input)

    # Assign your label text at runtime,
    _value = "101010"
    _form.rating.label.text = f"Your rating out of 10 e.g. {_value}"

    _label = _form.rating.label()  # get the generated label html
    _input = _form.rating()  # get the generated input html
    print(_label)
    print(_input)


if __name__ == "__main__":
    test_form()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM