Flask Tutorial
About Lesson

In this Flask Tutorial we are going to learn about Template Variable in Flask, sometimes we need to send data from our flask views to the html files, for this purpose we can use template variables. for example we are working with the database, we retrieve the data in our view function, after that by the help of template or context variable we can send the data to the template files. now in this example we are not going to use the data from the database, we are going to just send some predefined data from our Index view to the index.html.



Now this is our app.py file, we  are going to just bring changes in our Index view, because we want to send some data from Index view to our index.html.


So you can see that the function render_template provided by Flask integrates the Jinja2 template engine with the application. this function takes the filename of the template as its first argument. and the second one is the data that we want to send for index.html file, and you can see that i have sent just a simple predefined name value to my html file.



Now we want to get this data in our index.html, so these are our html files, you can use this {{}} syntax for getting the data from the view function to your index file.















Run your flask application and go to http://localhost:5000/, you can see the data in here.

Flask Tutorial - Template Variable in Flask
Flask Tutorial – Template Variable in Flask


Thank you for visiting my website! If you enjoyed the free courses, please consider supporting my works on Patreon.
Exercise Files
No Attachment Found
No Attachment Found