interview questions

When is the session in flask created and destroyed?

     1. When the request comes, the request and session will be encapsulated into a RequestContext object. After encapsulation into an object, the object will be put into the internal Local object through LocalStack.

     2. Because the session was empty when it was encapsulated at the beginning, the next step was open_session, and the value in the cookie was taken out and reassigned to ctx

     3. When finally returning, execute save_session, read out the session in ctx and serialize it, write it to the cookie to the user, and then remove ctx.

The life cycle of g in flask

      Created when the request comes in, destroyed when the request ends

Can g be used as a session?

  No, the session will still have value when it comes next time, but g will not be there when it comes next time. The session is taken in the cookie when it comes next time, but g only applies to one life cycle.

role of g

  a request global variable

Talk about your knowledge of Django and flask framework

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325065310&siteId=291194637
Recommended