Pass a Python + Flask variable in an HTML attribute

Question:

(Novice btw) I’m using Python + Flask

I have Python variable I want to place in as a substitute for a value=" "

My attempt: value="{{ variable }}" didn’t work

<form>
  <textarea value="{{ result }}"></textarea>
</form>
render_template("home.html", result=result) 

Any guidance appreciated.

Asked By: Empty

||

Answers:

Try <textarea>{{ result }}</textarea> instead of <textarea value="{{ result }}"></textarea>

Answered By: Luka Milic

https://www.w3schools.com/tags/tag_textarea.asp

textarea has only four attributes "id=", "name=", "rows=", "cols="

So, If you want to put python variable in html using jinja. Use,

<textarea>{{ result }}</textarea>

or

<textarea "id=", "name=", "rows=", "cols=">{{ result }}</textarea>
Answered By: rishabh11336
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.