python - flask_script manager 运行报错

 水门街口卖瓜子的 发布于 2022-10-26 15:50

利用flask框架进行个人主页开发,在manage.py中利用flask_script添加了shell运行命令,整个manage.py文件代码如下:

"""the launcher of the whole app"""
#!/usr/bin/env python
import os
from app import create_app, db
from flask.ext.script import Manager, Shell
from flask.ext.migrate import Migrate, MigrateCommand
from app.models import User

app = create_app(os.getenv('FLASK_CONFIG') or 'default')
manager = Manager(app)
migrate = Migrate(app, db)

def make_shell_context(): # initialize the running context of python shell
    return dict(app=app, db=db)

manager.add_command("shell", Shell(make_context=make_shell_context))
manager.add_command('db', MigrateCommand)

@manager.add_command
def test():
    """Run the unit tests."""
    import unittest
    tests = unittest.TestLoader().discover('tests')
    unittest.TextTestRunner(verbosity=2).run(tests)

if __name__ == "__main__":
    manager.run()

最后在终端执行python manage.py shell命令时,遇到报错如下:

Traceback (most recent call last):
  File "manage.py", line 27, in 
    manager.run()
  File "/home/curry/myproject/blog/venv/local/lib/python2.7/site-packages/flask_script/__init__.py", line 405, in run
    result = self.handle(sys.argv[0], sys.argv[1:])
  File "/home/curry/myproject/blog/venv/local/lib/python2.7/site-packages/flask_script/__init__.py", line 342, in handle
    app_parser = self.create_parser(prog)
  File "/home/curry/myproject/blog/venv/local/lib/python2.7/site-packages/flask_script/__init__.py", line 168, in create_parser
    command_parser = command.create_parser(name, parents=[options_parser])
AttributeError: 'function' object has no attribute 'create_parser'

似乎是flask_script本身运行出了问题,对于这种追溯到module源代码中的错误分析不太知道分析方法,希望有高人能够讲解一下,谢谢

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有