19. 調試模式
當使用Sanic的調試模式時,Sanic將會提供一個詳細的日誌輸出,同時會默認是使用Sanic的重載屬性。
**
注意⚠️: Sainc的調試模式會降低Sanic的性能,建議使用開發者模式。
**
(1)設置調試模式
設置調試模式代碼重載功能會被激活,同時會有一個詳細的日誌輸出。
from sanic import Sanic
from sanic.response import json
app = Sanic()
@app.route('/')
async def hello_world(request):
return json({"hello": "world"})
if __name__ == '__main__':
app.run(host="0.0.0.0", port=8000, debug=True)
(2)手動設置自動加載
Sanic提供了手動選項,設置auto_reload可以激活或者取消自動裝載函數。
from sanic import Sanic
from sanic.response import json
app = Sanic()
@app.route('/')
async def hello_world(request):
return json({"hello": "world"})
if __name__ == '__main__':
app.run(host="0.0.0.0", port=8000, auto_reload=True)