2

我试图使用flask fab 从终端创建一个新用户,但是当我运行命令并填写所有必需的信息usernameemailpassword我收到以下错误消息:AttributeError: 'Flask' object has no attribute 'appbuilder'

完整追溯:

https://pastebin.com/gACSfChG

FLASK_APP=run.py

运行.py

import os

from app import RubyAPP

config_name = os.getenv('FLASK_CONFIG')
app = RubyAPP(config_name).app()

if __name__ == '__main__':
    app.run(debug=True, host='0.0.0.0')

__init__.py

from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
from flask_login import LoginManager
from flask_login import current_user
from flask import render_template

db = SQLAlchemy()
app = Flask(__name__, instance_relative_config=True)
login_manager = LoginManager(app)

@app.errorhandler(404)
def not_found_404(e):
    return render_template('404.html'), 404

class RubyAPP(object):

    def __init__(self, config_name):
        # App manager
        app.config.from_pyfile('config.py')
        db.init_app(app)

        # Login manager
        login_manager.init_app(app)
        login_manager.login_message = 'You must be logged in to access this page'
        login_manager.login_view = 'auth.login'

        # Flask migrate
        migrate = Migrate(app, db)

    def app(self):
        # Error handling apps registers
        app.register_error_handler(404, not_found_404)

        # Models
        from app import models

        # Views
        from .home import home as home_blueprint
        app.register_blueprint(home_blueprint)

        from .profile.links import links as links_blueprint
        app.register_blueprint(links_blueprint)

        from .login import login as login_blueprint
        app.register_blueprint(login_blueprint)

        return app

我尝试重新安装appbuilder,但给出了同样的错误。我认为这两个文件就足够了,但是由于我不知道是什么给出了错误,所以如果您需要任何额外的文件,请告诉我。

4

1 回答 1

1

有同样的错误。您必须appbuilder.init_app()为您的应用程序运行:

..
..
class RubyAPP(object):
    def __init__(self, config_name):
        # App manager
        app.config.from_pyfile('config.py')
        db.init_app(app)

        with app.app_context():
            appbuilder.init_app(app, db.session)
..
..
于 2020-12-30T06:12:57.903 回答