close

How to display a variable in HTML

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How to display a variable in HTML in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How to display a variable in HTML?

  1. How to display a variable in HTML?

    This is very clearly explained in the Flask documentation so I recommend that you read it for a full understanding, but here is a very simple example of rendering template variables.

  2. display a variable in HTML

    This is very clearly explained in the Flask documentation so I recommend that you read it for a full understanding, but here is a very simple example of rendering template variables.

Method 1

This is very clearly explained in the Flask documentation so I recommend that you read it for a full understanding, but here is a very simple example of rendering template variables.

HTML template file stored in templates/index.html:

<html>
<body>
    <p>Here is my variable: {{ variable }}</p>
</body>
</html>

And the simple Flask app:

from flask import Flask, render_template

app = Flask('testapp')

@app.route('/')
def index():
    return render_template('index.html', variable='12345')

if __name__ == '__main__':
    app.run()

Conclusion

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read