Home > Enterprise >  not being able to pass a data from flask to html template
not being able to pass a data from flask to html template

Time:02-18

I'm using a very simple code to pass data from flask to html template but the value is not passed here is mi code

python code:

 @app.route("/",methods=['GET','POST']) 
 def home():
     if request.method=='GET':
         return render_template("base.html")
 
     if request.method=='POST':
         
 
         print('hello')
         resultat="helo"
         a=True
         return render_template("base.html",resultat=resultat)

html code:

<p> {%if a %} {{ resultat }} {% endif %} </p>

can someone help me please

CodePudding user response:

The problem is that you are not passing a to the template.

return render_template("base.html", resultat=resultat, a=a)

Also, did you mean result?

  • Related