Mike C.
Mike C.

Reputation: 1921

Populate a form using Flask / Jinja2 template. Input text fields are truncating data

I am trying to send data to Flask Jinja2 template and repopulate a text input inside of a form. When I do this my data gets truncated. For example:

App.py

@app.route('/test')
def test():    
    text = 'My long test entry'
    return render_template('test.html', text=text)

Template

<head>
  <title>test</title>  
</head>
<body>
  <form>
    test:<br>
    <input type="text" name="test" value={{text}}>    
  </form> 
</body>

Result

enter image description here

I want to populate with the entire string.

Upvotes: 0

Views: 2080

Answers (1)

noslenkwah
noslenkwah

Reputation: 1744

You'll need quotes around {{text}}

Here's what renders:

<input type="text" name="test" value=My long test entry>

Here's what you want to render:

<input type="text" name="test" value="My long test entry">

Here's what your code should look like:

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

Upvotes: 5

Related Questions