原文地址:https://sanicframework.org/en/guide/basics/app.html

    1. # path/to/server.py
    2. from sanic import Sanic
    3. app = Sanic("My Hello, world app")
    1. # Raises a warning as deprecated feature in 21.3
    2. app = Sanic("MyApp")
    3. app.db = Database()
    1. # Correct way to attach objects to the application
    2. app = Sanic("MyApp")
    3. app.ctx.db = Database()
    1. # ./path/to/server.py
    2. from sanic import Sanic
    3. app = Sanic("my_awesome_server")
    1. # ./path/to/somewhere_else.py
    2. from sanic import Sanic
    3. app = Sanic.get_app("my_awesome_server")
    1. app = Sanic.get_app(
    2. "non-existing",
    3. force_create=True,
    4. )
    1. Sanic("My only app")
    2. app = Sanic.get_app()
    1. app = Sanic('myapp')
    2. app.config.DB_NAME = 'appdb'
    3. app.config['DB_USER'] = 'appuser'
    4. db_settings = {
    5. 'DB_HOST': 'localhost',
    6. 'DB_NAME': 'appdb',
    7. 'DB_USER': 'appuser'
    8. }
    9. app.config.update(db_settings)
    1. app.config.GOOD = "yay!"
    2. app.config.bad = "boo"