flask

flask A framework that utilizes werkzeug and jinja2. Micro framework. Except for external libraries, it only supports around views.

Thread-local objects

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.

context

Various context objects can be accessed in a global format.

session

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.

configuration

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.

Return value

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

View functions depending on the format, such as render_template and jsonify.

Blueprint

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.

Parameter data conversion and validation

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

flask
flask
First Flask
Flask initial settings
Flask development introduction
Notes on Flask
Flask basic memo
Flask redis proxy
Flask database settings
Flask Basic authentication
Flask Tutorial # 1 ~ GET Request ~
Easy to use Flask
Flask Tutorial # 3 ~ DB Linkage ~
IP restrictions with Flask
jsonschema validation on flask
Suppress python3 flask logging
Flask article summary page
Customize Flask access logs
Flask site construction memorandum
Hello world with flask
Flask HTML template settings
Run Apache2 + WSGI + Flask
Programming with Python Flask
Image uploader in Flask
gae flask skeleton stand
Flask introduction-Blueprint application memo