Home > front end >  How to input a Python Flask variable into html tag attribute
How to input a Python Flask variable into html tag attribute

Time:12-06

(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.

CodePudding user response:

As per chipchap31's comment: remember to pass in the variable into your render_template method like so:

variable = "foo"

render_template("page.html", variable=variable)

Once you've passed this in, you can access it in your Jinja template (HTML) like so:

<tag value="{{ variable }}"/>

CodePudding user response:

Solution: Due to textarea not having a "value" attribute simply putting the Python variable between the tags will work.

<textarea>{{ result }}</textarea>
  • Related