samedi 26 octobre 2019

AttributeError when running a flask app in flask shell

I have finished a flask app. When I run it by python run.py, the app can work perfectly.

But when I want to open flask shell by flask shell or even just flask, it tell me:

Traceback (most recent call last):
  File "f:\programs\anaconda\envs\web\lib\site-packages\flask\cli.py", line 556, in list_commands
    rv.update(info.load_app().cli.list_commands(ctx))
  File "f:\programs\anaconda\envs\web\lib\site-packages\flask\cli.py", line 388, in load_app
    app = locate_app(self, import_name, name)
  File "f:\programs\anaconda\envs\web\lib\site-packages\flask\cli.py", line 257, in locate_app
    return find_best_app(script_info, module)
  File "f:\programs\anaconda\envs\web\lib\site-packages\flask\cli.py", line 83, in find_best_app
    app = call_factory(script_info, app_factory)
  File "f:\programs\anaconda\envs\web\lib\site-packages\flask\cli.py", line 117, in call_factory
    return app_factory(script_info)
  File "C:\Users\zkhp\Desktop\flask-bigger-master\backend\startup.py", line 41, in create_app
    app.config['SECRET_KEY'] = config.get('secret', '!secret!')
AttributeError: 'ScriptInfo' object has no attribute 'get'

The last sentence is here:

def create_app(config):
    app = Flask(
        __name__,
        template_folder=template_folder,
        static_folder=static_folder
    )
    app.config['SECRET_KEY'] = config.get('secret', '!secret!')

The config is a dictionary, which is given by:

def start_server(run_cfg=None, is_deploy=False):
    config = {
        'use_cdn': False,
        'debug': run_cfg.get('debug', False),
        'secret': md5('!secret!'),
        'url_prefix': None,
        'debugtoolbar': True
    }
    app = create_app(config)

I am confused with how the dictionary config is transformed to be a ScriptInfo?

And what should I do to solve the problem?

Thanks for your patient reading!




Aucun commentaire:

Enregistrer un commentaire