flask A framework that utilizes werkzeug and jinja2. Micro framework. Except for external libraries, it only supports around views.
Use werkzeug.local to make request etc. look like a global object. → Is this to make it accessible from anywhere? Of course, the implementation code is complicated.
**? How is LocalProxy ensured to be thread safe? ** ** → Since the Local object manages the data using the id obtained by the thread.get_ident or gleenlet.get_current function as the key, the same key update does not occur from multiple threads.
Various context objects can be accessed in a global format.
I don't use the werkzeug session module at all. SessionInterface and SessionCookieSession are the keys. SessionInterface is responsible for operations such as session creation and storage, and SessionCookie has session information. The session is held in RequestContext.
Since the operation and data are separated, it seems to be anti-object oriented at first glance, but if you think of it as one module called sessions.py, it may not be so.
Access the Config instance through the app.config object. Since the config object is a subclass of dict, you can set values that are not set on the flask side. By setting ConfigAttribute to the application object, it is possible to access some setting values from the application object. ConfigAttribute only acts as an intermediary to the config instance. The need is doubtful.
There seems to be a loose rule that describes the return value as rv. In a function with long processing, it is easy to understand what is the return value, but since there is no information other than the return value in the name rv, readability is reduced unless the return value is specified first.
View functions depending on the format, such as render_template and jsonify.
Ability to extend the operation of the application. It is possible to create a base application or divide a large application into multiple URL roots.
wtforms The validation framework introduced in flask.
Data conversion is performed when the Form instance is created (process), and validation is performed when the validate method is executed. However, even if an error occurs during data conversion, only the error information is retained and the exception is not propagated. It will be merged when validate is executed.
Recommended Posts