【发布时间】:2021-03-21 13:55:37
【问题描述】:
这是我的代码块:
下面的一个是覆盖 Flask Blueprint 并添加属性 config 来复制应用程序的配置。
# Overriding Flask Blueprint
from flask import Blueprint
class CustomBlueprint(Blueprint):
def __init__(self, name, import_name):
super().__init__(name, import_name)
self.config = None
self.guard = None
def register(self, app, options, first_registration=False):
self.config = app.config
self.guard = app.guard
print(self.guard) # Works Fine
print(self.config) # Works Fine
super(CustomBlueprint, self).register(app, options, first_registration)
下面一个正在使用该类。
from src.SHARED.overriden.blueprint import CustomBlueprint
from .guard import module_guard
example = CustomBlueprint('EXAMPLE', __name__)
print(example.config) # Here is the problem: It prints None
@example.route('/')
@module_guard
def hello_example():
return "Example is Working !!"
我也尝试了另一种方法,使用 @property、getter 和 setter。但这会产生错误,
属性错误:无法添加属性
我想访问/打印app.config,我应该怎么做??
【问题讨论】: