我有一个 Sanic 应用程序,想app.config
从蓝图中检索它MONGO_URL
,我会将它从蓝图中传递给存储库类。
但是,我找不到如何进入app.config
蓝图。我还检查了 Flask 解决方案,但它们不适用于 Sanic。
我的app.py
:
from sanic import Sanic
from routes.authentication import auth_route
from routes.user import user_route
app = Sanic(__name__)
app.blueprint(auth_route, url_prefix="/auth")
app.blueprint(user_route, url_prefix="/user")
app.config.from_envvar('TWEETBOX_CONFIG')
app.run(host='127.0.0.1', port=8000, debug=True)
我的auth blueprint
:
import jwt
from sanic import Blueprint
from sanic.response import json, redirect
from domain.user import User
from repository.user_repository import UserRepository
...
auth_route = Blueprint('authentication')
mongo_url = ?????
user_repository = UserRepository(mongo_url)
...
@auth_route.route('/signin')
async def redirect_user(request):
...