Debug Mode

When enabling Sanic’s debug mode, Sanic will provide a more verbose logging output and by default will enable the Auto Reload feature.

警告

Sanic’s debug more will slow down the server’s performance and is therefore advised to enable it only in development environments.

Setting the debug mode

By setting the debug mode a more verbose output from Sanic will be outputed and the Automatic Reloader will be activated.

  1. from sanic import Sanic
  2. from sanic.response import json
  3.  
  4. app = Sanic()
  5.  
  6. @app.route('/')
  7. async def hello_world(request):
  8. return json({"hello": "world"})
  9.  
  10. if __name__ == '__main__':
  11. app.run(host="0.0.0.0", port=8000, debug=True)

Manually setting auto reload

Sanic offers a way to enable or disable the Automatic Reloader manually, the auto_reload argument will activate or deactivate the Automatic Reloader.

  1. from sanic import Sanic
  2. from sanic.response import json
  3.  
  4. app = Sanic()
  5.  
  6. @app.route('/')
  7. async def hello_world(request):
  8. return json({"hello": "world"})
  9.  
  10. if __name__ == '__main__':
  11. app.run(host="0.0.0.0", port=8000, auto_reload=True)

內容目录

Related Topics

本页