Python Flask – Introduction to Flask Templates

This is our second tutorial in Python Flask, in this tutorial we are going to have Introduction to Flask Templates, so for this Flask looks for the templates folder inside the application folder.

 

If you are interested in Web Development with Django Framework, than you can read

the complete articles with video training in this link,  Django Web Development Tutorials.

 

 

Also in the previous tutorial we had a complete introduction to Flask Web Framework,

you can check this link Flask Introduction & Installation.

 

 

The first step is that create a new folder at name of templates, make sure that it has the

same spelling, if you don’t do this, you will not see the content of your template.

 

After that you need to create an html file in your templates folder, iam going to create two html files, the first one is index.html and the second one is contact.html.

 

 

 

 

OK now this is our app.py file, and we have rendered our templates in our view functions.

 

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.
Any additional arguments are key/value pairs that represent actual values for variables referenced in the template.

 

OK now let’s create our html files.

 

 

 

 

templates/index.html 

 

 

 

 

 

templates/contact.html

 

 

 

 

If you run your project this will be the result

 

 

 

http://localhost:5000/

Python Flask - Introduction to Flask Templates
Python Flask – Introduction to Flask Templates

 

 

 

 

 

http://localhost:5000/contact

Python Flask - Introduction to Flask Templates
Python Flask – Introduction to Flask Templates

 

 

 

 

 

Also you can watch my complete 4 hours training on Flask Web Development

 

 

Subscribe and Get Free Video Courses & Articles in your Email

 

Comments are closed.

Share via
Copy link
Powered by Social Snap
×