原文地址:https://sanicframework.org/en/guide/basics/app.html
# path/to/server.pyfrom sanic import Sanicapp = Sanic("My Hello, world app")
# Raises a warning as deprecated feature in 21.3app = Sanic("MyApp")app.db = Database()
# Correct way to attach objects to the applicationapp = Sanic("MyApp")app.ctx.db = Database()
# ./path/to/server.pyfrom sanic import Sanicapp = Sanic("my_awesome_server")
# ./path/to/somewhere_else.pyfrom sanic import Sanicapp = Sanic.get_app("my_awesome_server")
app = Sanic.get_app( "non-existing", force_create=True,)
Sanic("My only app")app = Sanic.get_app()
app = Sanic('myapp')app.config.DB_NAME = 'appdb'app.config['DB_USER'] = 'appuser'db_settings = { 'DB_HOST': 'localhost', 'DB_NAME': 'appdb', 'DB_USER': 'appuser'}app.config.update(db_settings)
app.config.GOOD = "yay!"app.config.bad = "boo"