For develop some internal tools.
reference docs
- https://flask.palletsprojects.com/en/1.1.x/
- https://flask-appbuilder.readthedocs.io/en/latest/intro.html
- https://github.com/luhuisicnu/The-Flask-Mega-Tutorial-zh 2017年新版The Flask Mega-Tutorial教程
pyvenv
Recommend to use pyvenv to develop flask, easy to manage the python version and packages
1 | python3 -m venv /path/to/new/virtual/environment |
install flask
- https://flask-appbuilder.readthedocs.io/en/latest/installation.html#
- https://flask.palletsprojects.com/en/1.1.x/installation/#installation
1 | # under virtual env |
SQLAlchemy
- English Documentation https://docs.sqlalchemy.org/en/13/index.html
- 中文文档 https://www.osgeo.cn/sqlalchemy/index.html
Sometimes, if it’s not easy to add constriant condition on model.py in database level, we can try from application level by built-in methods pre_add https://flask-appbuilder.readthedocs.io/en/latest/api.html#flask_appbuilder.baseviews.BaseCRUDView.pre_add
security
Put sensitive data in file .env
1 | SECRET_KEY=secret key |
Use os module method getenv()
1 | import os |
issue
UNIQUE Index by UniqueConstraint https://stackoverflow.com/questions/10059345/sqlalchemy-unique-across-multiple-columns
One issue in update row https://github.com/dpgaspar/Flask-AppBuilder/issues/1397
has_key dict check key
if there is error in log.info( error program ), console will not show that
error example: finally is None
1
2
3
4
5
6
7
8
9def cut_string(s: str) -> str:
begin = s.find(",")
end = s.rfind(",")
s = s[begin + 1:end]
if len(s) > 255:
cut_string(s)
else:
return sflake8 complains on boolean comparison “==” in filter clause sqlalchemy query condition is false