1

I am trying to design a web page with web-framework flask. This is the basic representation of the problem I faced.

app.py

app = Flask(__name__)

@app.route('/')
def home():
    return render_template('main.html', value="Utkarsh Prakash") 

@app.route('/approved', methods = ['POST', 'GET'])
def approved():
    return "Done"

if __name__ == '__main__':
    app.run(debug = False, threaded=False) 

main.html

<HTML>
    <BODY>
        <FORM action = "/approved" method = "POST">
            {{value}}
            <INPUT type="text" name="text" value={{value}}>
            <INPUT type = "Submit">
        </FORM>
    </BODY>
</HTML>

I just want the value which I am rendering from my flask code to be passed as predefined value of my text input file. Although {{value}} is containing both the words "Utkarsh Prakash", my input text field only contains one word, i.e., "Utkarsh".

enter image description here

How can I display both the words in the input text area?

1 Answer 1

4

Problem is in your main.html, you didn't quote the attribute value, so the result of your template is

<input type="text" name="text" value=Utkarsh Prakash>

Just change your template so it has value="{{ value }}"

<input type="text" name="text" value="{{ value }}">

edited code:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<form action = "/approved" method = "POST">
            {{value}}
            <input type="text" name="text" value="{{ value }}">
            <input type = "Submit">
        </form>
</body>
</html>

One more thing, please change all the uppercase html tags to lower case.

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.