WIP
Since I often write web servers using Flask, I will summarize the pages that I often refer to. I think it will be a collection of links for the time being, but if I have time, I would like to add more content. (It's about time to use FastAPI)
About SECRET_KEY
For official tutorials, it's best to use ʻos.urandom (12) `, which is a ** anti-pattern **
When running gunicorn with multiple Workers, Session and CSRF Protection (Flask-WTF) do not work properly because different SECRET_KEY is set depending on the worker.
session
In Vanilla Flask with no plugins
should be set to
SecretKey`, but this only uses this key in the hash calculation to prevent tampering with the contents stored in session. , The contents of session itself are not encrypted.server session You need to install a plugin. Backend options for saving sessions include Redis, other NoSQL, FileSystem, SQL, etc.
As a famous plug-in
and so on. FLask-Session accesses the backend that holds the Session from within Flask, but Beaker acts as middleware for the WSGI (eg Gunicorn) used. The latter also provides a Cache function. It has been confirmed that Flask-Session does not work properly when SQLAlchemy is specified as the backend (that is, SQL). (As of May 2020.5)
logging Flask and its plugins often provide a log output feature. To capture the output log with the Flask main unit log handle and output it
import logging
from flask.logging import default_handler #Log handler for flask body
#Other import etc.
from flask_cors import CORS
def create_app():
# init_Various processing such as app
#Here, the plugin you want to log`flask_cors`To
cors_err_lggr = logger.getLogger('flask_cors')
#Most plugins have the name of the built-in logger__name__Is it specified in?
cors_err_lggr.setLever(logging.DEBUG)
#Added default log handler
cors_err_lggr.addHandler(default_handler)
#Other processing
return app
test
When setting independent columns (columns that are not Foreign Keys) in the intermediate table of many: many, it is better to use ʻassociation_proxy than to use
relation`.
Official Doc for association_proxy, with implementation example
Official Document It feels like Capistrano or Deployer Explanatory article 1 Explanatory article 2
No, FastAPI Isn't it good?
Recommended Posts