Python:Flask自动刷新页面livereload

pip install livereload

文档:https://pypi.org/project/livereload/

代码

#coding=utf-8

from flask import Flask
from flask_script import Manager


app = Flask(__name__)

# 使用manager管理工具
manager = Manager(app)

@app.route("/")
def upload():
    return "hello nihao"

# 实现自动刷新调试功能
@manager.command
def dev():
    from livereload import Server
    live_server = Server(app.wsgi_app)
    live_server.watch("**/*.*")
    live_server.serve(open_url=True)


if __name__ == "__main__":
    manager.run()

#python main.py dev

或者

from livereload import Server


if __name__ == '__main__':
    app.debug = True
    live_server = Server(app.wsgi_app)
    # live_server.watch('**/*.*')
    live_server.serve(open_url_delay=True)
    # app.run()

参考
flask-script实现自动刷新页面调试

©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页