Templates
- Templates are functions with detailed API.
- These templates can generste any kind of output.
- {{variable_name}} is the syntax for substituting value to a variable.
- Below is an example of jinja2 templates.
python template code
- Example 1
1 2 3 4 5 6
from jinja2 import Template t = Template ("Hello {{name1}} welcome!") # {{name1 value is assigned}} print(t.render(name1 ="Banu"))# name1 is the variable name t = Template ("your age is {{age}}") print(t.render(age = input("Enter your Age")))# age value is assigned based on the values given in input prompt
Output
- Hello Banu welcome!
- Enter your Age13
- your age is 13
Example 2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
Output
-
IITM University
-
course name MAD 1
- course name MAD 2
Reference
Authors(Git):Devi(98.0%), Thejesh GN(2.0%)