flask小技巧

“(venv) $ export FLASK_APP=hello.py
(venv) $ export FLASK_DEBUG=1
(venv) $ flask run”

如下,当设置debug为1,允许reloader和debug两种模式,在reloader模式下,程序会自动检测code里的修改,非常方便的功能。

“(venv) $ flask run --help
Usage: flask run [OPTIONS]

  Runs a local development server for the Flask application.

  This local server is recommended for development purposes only but it can
  also be used for simple intranet deployments.  By default it will not
  support any sort of concurrency at all to simplify debugging.  This can be
  changed with the --with-threads option which will enable basic
  multithreading.

  The reloader and debugger are by default enabled if the debug flag of

Options:
  -h, --host TEXT                 The interface to bind to.
  -p, --port INTEGER              The port to bind to.
  --reload / --no-reload          Enable or disable the reloader.  By default
                                  the reloader is active if debug is enabled.
  --debugger / --no-debugger      Enable or disable the debugger.  By default
                                  the debugger is active if debug is enabled.
  --eager-loading / --lazy-loader
                                  Enable or disable eager loading.  By default
                                  eager loading is enabled if the reloader is
                                  disabled.
  --with-threads / --without-threads
                                  Enable or disable multithreading.
  --help                          Show this message and exit.”

Git 小技巧

获取第二章的sample代码

git checkout v0.2

从0.1切换到0.2时,出现如下告警

git checkout v0.2
error: Your local changes to the following files would be overwritten by checkout:
        app/routes.py
Please commit your changes or stash them before you switch branches.
Aborting

我选择放弃本地修改,切换到其他章节的代码,还有几种备选方案,可以看参考。

git reset --hard
HEAD is now at 23b3fc8 Chapter 1: Hello, World! (v0.1)
(venv) XXXXXX microblog % git checkout v0.2
Previous HEAD position was 23b3fc8 Chapter 1: Hello, World! (v0.1)
HEAD is now at 5d45592 Chapter 2: Templates (v0.2)

参考

you have three options:

Commit the change using
git commit -m "My message"
Stash it.
Stashing acts as a stack, where you can push changes, and you pop them in reverse order.

To stash, type

git stash
Do the merge, and then pull the stash:

git stash pop
Discard the local changes
using git reset --hard
or git checkout -t -f remote/branch

Or: Discard local changes for a specific file
using git checkout filename