本文flask==1.0.2python
一、導入extension包flask
from flask_script import Manager
二、使用manager管理工具app
app = Flask(__name__) # 使用manager管理工具 manager = Manager(app)
三、配置自動刷新路由工具
# 實現自動刷新調試功能 @manager.command def dev(): from livereload import Server live_server = Server(app.wsgi_app) live_server.watch('**/*.*') live_server.serve(open_url=True)
四、跑起來url
if __name__ == '__main__': # app.run() # 調試模式 # app.run(debug=True) #使用manager管理工具 manager.run()
五、在虛擬環境條件下運行spa
python app.py dev
(flask_pro) E:\PycharmProjects\flask_pro>python app.py dev [I 180804 10:02:39 server:292] Serving on http://127.0.0.1:5500 [W 180804 10:02:39 server:299] Use `open_url_delay` instead of `open_url` [I 180804 10:02:39 handlers:59] Start watching changes [I 180804 10:02:39 handlers:61] Start detecting changes
這樣,當你更改後,能夠實現自動刷新調試程序。debug
六、或者直接這樣(不用上面的方法)調試
from livereload import Server if __name__ == '__main__': live_server = Server(app.wsgi_app) live_server.watch('**/*.*') live_server.serve(open_url_delay=True) # app.run()
而後在虛擬環境條件下輸入,運行python app.pycode
(flask_moban) E:\PycharmProjects\flask_moban>python app.py
[I 180804 13:18:42 server:292] Serving on http://127.0.0.1:5500
具體參考官網Flask Extensionserver