Flash messages flashed in the official explanation is used to give users feedback. But in fact, this function is only a method of recording messages, in a request to record the message, in the next request to get the message, and then do the corresponding processing, that is, flask only exist in two adjacent requests "Flash", the third request does not exist this flash.
Let's use an example to illustrate how a "flash" is.
First introduce the Flash and Get_flashed_message methods
from Flask import flask,url_for,render_template,request,make_response,session, \
Flash,get_flashed_messages
Then we define two methods, one for recording Flash, and one for displaying flash.
@app. Route ("/addflash")
Addflash ():
???? Flash ("Bling Bling")
"added a Flash"
@app. Route ("/getflash/")
Getflash ():
???? Msgs = Get_flashed_messages ()
""
Msgs
???????? MsgStr + = msg+","
MsgStr
Then we run the program, first visit/addflash this address, the effect is as follows:
By the logic of the code, this should be a record of a bling bling flash, and then we get this flash in/getflash.
As you can see, we get to the Bling bling this flash. As mentioned above, this flash exists only in two requests, that is to say, if we refresh a/getflash, re-launch a request, bling Bling This flash should be not get, below we refresh the page to do a verification, after the effect of the refresh is as follows:
The page is blank, indicating that bling bling This flash is indeed not obtained by this request.
There is also a type parameter for Flash, which can be used to handle different types of flash, and the specific application can refer to the official documentation:
Http://docs.jinkan.org/docs/flask/patterns/flashing.html#message-flashing-pattern
Further into the layer, we go into the definition of flash will find, in fact, the Flash is the bottom of the session to achieve.
More articles about the public number "kick genius"
Application of Flash in Python web development-flask