如何在app.config
内访问FlaskGroup
?
FlaskGroup
的设置如下,
cli = FlaskGroup(create_app=create_app)
这样,在已注册的命令中,您可以访问应用程序配置,
@cli.command('run_worker')
def run_worker():
# 1. This did not provide a meaningful clue
print(dir(cli))
# 2. How to access the config without instantiating the app?
redis_url = app.config['REDIS_URL']
供参考,1.,产量
['__call__', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_load_plugin_commands', '_loaded_plugin_commands', 'add_command', 'add_help_option', 'allow_extra_args', 'allow_interspersed_args', 'callback', 'chain', 'collect_usage_pieces', 'command', 'commands', 'context_settings', 'create_app', 'deprecated', 'epilog', 'format_commands', 'format_epilog', 'format_help', 'format_help_text', 'format_options', 'format_usage', 'get_command', 'get_help', 'get_help_option', 'get_help_option_names', 'get_params', 'get_short_help_str', 'get_usage', 'group', 'help', 'hidden', 'ignore_unknown_options', 'invoke', 'invoke_without_command', 'list_commands', 'load_dotenv', 'main', 'make_context', 'make_parser', 'name', 'no_args_is_help', 'options_metavar', 'params', 'parse_args', 'resolve_command', 'result_callback', 'resultcallback', 'set_debug_flag', 'short_help', 'subcommand_metavar']
我想完成2,最好不必先做cli.create_app
。