我有一个app.py烧瓶应用程序,我想启用自动重新加载.这是切入点:
APP = Flask(__name__)
APP.config.from_object(os.environ['APP_SETTINGS'])
# a lot of configurations ommited
if __name__ == "__main__":
APP.run(debug=True, port=5005)
Run Code Online (Sandbox Code Playgroud)
当我运行应用程序时,我在终端中得到了这个:
/Users/George/myproject/venv/bin/python /Users/George/myproject/app.py
* Running on http://127.0.0.1:5005/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
* Debugger pin code: 338-825-330
Run Code Online (Sandbox Code Playgroud)
当我修改我的一个控制器时,它会发现发生了一个变化:
* Detected change in '/Users/George/myproject/web_endpoints/user.py', reloading
Run Code Online (Sandbox Code Playgroud)
但是没有发生变化,如果我做了另一次更改,它永远不会被接收(在终端中没有报告).
Flask 不建议使用 app.run() 进行自动重新加载,因为这很难得到支持
这是Flask源码中的注释
def run(self, host=None, port=None, debug=None, load_dotenv=True, **options):
"""Runs the application on a local development server.
...
If you want to run the application in debug mode, but disable the
code execution on the interactive debugger, you can pass
``use_evalex=False`` as parameter. This will keep the debugger's
traceback screen active, but disable code execution.
It is not recommended to use this function for development with
automatic reloading as this is badly supported. Instead you should
be using the :command:`flask` command line script's ``run`` support.
...
"""
pass
Run Code Online (Sandbox Code Playgroud)
但你可以强制使用重新加载器,如下所示:
def run(self, host=None, port=None, debug=None, load_dotenv=True, **options):
"""Runs the application on a local development server.
...
If you want to run the application in debug mode, but disable the
code execution on the interactive debugger, you can pass
``use_evalex=False`` as parameter. This will keep the debugger's
traceback screen active, but disable code execution.
It is not recommended to use this function for development with
automatic reloading as this is badly supported. Instead you should
be using the :command:`flask` command line script's ``run`` support.
...
"""
pass
Run Code Online (Sandbox Code Playgroud)
注意,app.run()必须用 包裹起来if __name__ == '__main__'。
| 归档时间: |
|
| 查看次数: |
430 次 |
| 最近记录: |