Flask
source link: https://feiyang233.club/post/flask/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
费洋的博客
Flask
For develop some internal tools.
reference docs
pyvenv
Recommend to use pyvenv to develop flask, easy to manage the python version and packages
1
2
3
python3 -m venv /path/to/new/virtual/environment
source /path/to/new/virtual/environment
install flask
1
2
3
4
5
6
7
8
# under virtual env
pip install Flask
pip install flask-appbuilder
flask fab create-app
flask run
SQLAlchemy
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
2
3
import os
secret_key = os.getenv("SECRET_KEY","default value")
issue
- Use JSON
- 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
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK