1.jinja2 Template engine
1.Flask looking for a template in the Templates subfolder of the program folder
2. Template Rendering
The first parameter of the 1.render_template function is the file name of the template. The subsequent parameters are key-value pairs that represent the true values of the variables in the template.
@app. Route ('/user/<name>')def User (name): return render_template ('user.html', Name=name)
The "name" on the left indicates the parameter name, which is the placeholder used in the template, and the right "name" is a variable in the current scope that represents the value of the parameter with the same name.
2.JINJA2 provides some filters
Hello, {{name|capitalize}}
Safe renders values without escaping
Capitalize converts the first letter of the value to uppercase, and the other letters to lowercase
Lower converting values to lowercase
Upper convert values to uppercase
Title converts the first letter of each word in the value to uppercase
Trim to remove the end and end spaces of the value
Striptags all HTML tags in a value before rendering
3. Control Interface
{% if user%} Hello, {{User}}! {% Else%} Hello, stranger!. {% ENDIF%}
< ul > {% for comment in comments%} <li>{{comment}}</ li> </ul >
Flask Notes (2)