A flask boilerplate demo for using flask-app
- Run
pip install pipenv
- Run
pipenv install --dev
cp .env.sample .env
- Update the
.env
file with the respective variables
$ pipenv shell
# call flask CLI in the shell
$ flask --version
Python 3.7.7
Flask 1.1.2
Werkzeug 1.0.1
- Run
flask create-db
to create database - Run
flask db upgrade
to create table and apply migrations
- Run
flask routes
Endpoint Methods Rule
---------- --------- -----------------------
static GET /static/<path:filename>
user.users GET, POST /users/
user.users GET /users/<int:user_id>
- Run
flask test
- Run
flask shell
>>> from api.models import *
>>> User.create(username='admin', first_name='Ming', last_name='Li')
>>> User.query.count()
1
- Run
flask run
* Serving Flask app "manage.py" (lazy loading)
* Environment: development
* Debug mode: on
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
* Debugger PIN: 621-366-433
PENDING
run linter
$ flask dev lint
run linter and generate html report
$ flask dev lint --html-report=tmp/dev/report/pylint-report.html
config lowest lint score, useful for CI
$ flask dev lint --lowest-score=8.0
# $? will be none-zero if pylint_score is lower then lowest_score
reformats codes to follow the Google Python Style Guide
$ flask dev format
Run formatter
No changes needed.
# $? will be non-zero if some files need to be changed
format codes and make changes to files in place
$ flask dev format --in-place
Run formatter
[NOTICE]Make changes to files in place!
$ flask dev security_audit
# $? will be non-zero if found security issues
run security audit and generate html report
$ flask dev security_audit --html-report=tmp/dev/report/bandit-report.html
manage packages with pipenv and Pipfile
# displays currently-installed dependency graph information in Pipfile.lock
$ pipenv graph
# list required packages in requirements format
$ pipenv run pip freeze
$ pipenv install [--dev] <package>~=major.minor
# e.g.:
$ pipenv install --dev pylint-report~=0.1.8
# upgrade a package in Pipfile
$ pipenv install --keep-outdated [--dev] <package>~=x.y.z
# e.g.:
$ pipenv install --keep-outdated --dev pylint-report==0.1.8
# upgrade a package and auto update Pipfile.lock
$ pipenv update --keep-outdated <pkg>
# e.g.:
$ pipenv update --keep-outdated pylint-report
just update Pipfile.lock for the new package requirements
# records the new requirements to the Pipfile.lock file
# pipenv lock --keep-outdated
NOTES: DO NOT update Pipfile.lock manually, should always update it by running pipenv
command
$ pipenv uninstall --keep-outdated <package>