0

How do I set the VALUE attribut of a text input field (HTML forms).

I tried it with:

Python:

@app.route("/function_a", methods=['GET', 'POST'])
def function_a():
    form = ReusableForm(request.form)
    query = "test value"
    if request.method == 'POST':
    name=request.form['name']
    return render_template('zeit.html', form=form, query_test=query)

HTML template:

{{ form.name(value="{{ query_test }}") }}

the website output is like:

<input id="name" name="name" required type="text" value="{{query_test}}">

expected website output:

<input id="name" name="name" required type="text" value="test value">
3
  • ReusableForm is a class so instead of setting the value in the template do it in python code. form.name="test value" Commented Nov 6, 2018 at 12:20
  • It is still the same output without a value. Commented Nov 6, 2018 at 13:20
  • In the template delete setting value, make sure you have only {{ form.name }} Commented Nov 6, 2018 at 13:22

1 Answer 1

5

I got the solution:

in the HTML template I wrote only the variable without the brackets.

{{ form.name(value=query_test) }}

and the output is like I want it:

<input id="name" name="name" required type="text" value="test value">
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.