Reload Flask app when template file changes

前端 未结 10 1671
栀梦
栀梦 2020-11-27 13:04

By default, when running Flask application using the built-in server (Flask.run), it monitors its Python files and automatically reloads the app if its code cha

10条回答
  •  醉话见心
    2020-11-27 13:32

    Updated as of June 2019:

    The flask CLI is recommended over app.run() for running a dev server, so if we want to use the CLI then the accepted solution can't be used.

    Using the development version of Flask (1.1) as of this writing allows us to set an environment variable FLASK_RUN_EXTRA_FILES which effectively does the same thing as the accepted answer.

    See this github issue.

    Example usage:

    export FLASK_RUN_EXTRA_FILES="app/templates/index.html"
    flask run
    

    in Linux. To specify multiple extra files, separate file paths with colons., e.g.

    export FLASK_RUN_EXTRA_FILES="app/templates/index.html:app/templates/other.html"
    

    The CLI also supports an --extra-files argument as of Flask 1.1.

提交回复
热议问题