【发布时间】:2019-12-13 01:59:40
【问题描述】:
我正在尝试使用“Flask run”将应用程序部署到在我的本地计算机上运行良好的 heroku。我的应用程序的结构类似于带有蓝图的微博烧瓶教程。当我部署它然后尝试访问该网站时,我收到此错误:
TypeError: create_app() takes from 0 to 1 positional arguments but 2 were given
这是我的 __init__.py 文件:
db = SQLAlchemy()
migrate = Migrate()
login = LoginManager()
login.login_view = 'auth.login'
login.login_message = 'Please log in to access this page.'
bootstrap = Bootstrap()
uploadFolder = os.path.dirname(__file__) + '/uploads/companies'
def create_app(config_class=Config):
app = Flask(__name__)
app.config.from_object(config_class)
db.init_app(app)
migrate.init_app(app, db)
login.init_app(app)
bootstrap.init_app(app)
from app.errors import bp as errors_bp
app.register_blueprint(errors_bp)
from app.auth import bp as auth_bp
app.register_blueprint(auth_bp, url_prefix="/auth")
from app.main import bp as main_bp
app.register_blueprint(main_bp, url_prefix="/")
if not app.debug and not app.testing:
if not os.path.exists('logs'):
os.mkdir('logs')
file_handler = RotatingFileHandler('logs/StructuredSafety.log', maxBytes=10240,
backupCount=10)
file_handler.setFormatter(logging.Formatter(
'%(asctime)s %(levelname)s: %(message)s [in %(pathname)s:%(lineno)d]'))
file_handler.setLevel(logging.INFO)
app.logger.addHandler(file_handler)
app.logger.setLevel(logging.INFO)
app.logger.info('Structured Safety startup')
return app
from app import models
我的 app.py 文件是:
from app import create_app as application
from app import db
from app.models import User
app = application
我的 Procfile 看起来像这样:
web: flask db upgrade; gunicorn StructuredSafety:app
我一直在努力在网上寻找有关此问题的资源。我知道我的 app.py 文件正在调用 create_app,但我没有在其中传递任何内容,所以我很好奇 create_app 实际是从哪里调用的,以及为什么它会接收到许多参数。
【问题讨论】: