Special variables and methods of the template of flask

Source: Internet
Author: User

3.6 Special variables and methods in flask:

In flask, there are special variables and methods that can be accessed directly in the template file.

Config object:

The Config object is the Config object for flask, which is the App. Config object. {{config. Sqlalchemy_database_uri}}

Request object:

is the request object in Flask that represents the currently requested, and the request object holds all the information for an HTTP request.

The properties commonly used for request are as follows:

Properties Description type
Data Record the requested data and convert it to a string *
Form Record form data in a request Multidict
Args Log query parameters in a request Multidict
Cookies Record cookie information in a request Dict
Headers Record the headers in the request Environheaders
Method Log the HTTP method used by the request Get/post
Url Record the URL address of the request String
Files Record requests for uploaded files *
{{Request.url}}

Url_for Method:

Url_for () returns the URL of the incoming route function, which is the function that is decorated by the App.route () routing decorator. If we define a route function with parameters, you can pass these parameters as named arguments.

{{url_for ('index')}}{{url_for ('post', post _id=1024)}}

Get_flashed_messages Method:

Returns a list of information that was previously passed through Flash () in flask. The message represented by the string object is added to a message queue and then taken out by calling the Get_flashed_messages () method.

 for  in Get_flashed_messages ()%}    {{message}}{% endfor%}



Special variables and methods of the template of flask

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.