Flask Notes (2)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.