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