-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Delayed initialization — init_app() not working #203
Comments
you should add_resource first, then init_app .
|
That's a bit weird and need some refactoring.
Flask-kit: def get_app(self, app_module_name, **kwargs):
self.app = Flask(app_module_name, **kwargs)
self.app.config.from_object(self.app_config)
self._generate_db_mapping()
self._bind_extensions()
self._register_blueprints()
self._register_context_processors() My other app written with some boilerplate: def app_factory(config, app_name=None, blueprints=None):
app_name = app_name or __name__
app = Flask(app_name)
config = config_str_to_obj(config)
configure_app(app, config)
configure_database(app)
configure_cache(app)
configure_blueprints(app, blueprints or config.BLUEPRINTS)
configure_error_handlers(app)
configure_extensions(app)
configure_context_processors(app)
configure_template_filters(app)
configure_before_request(app)
configure_views(app)
return app |
Had the same issue. What is misleading are the explanations:
If you look at the code of the add_ressource function:
adding a ressource is self.app is not defined add it to a list-like object and when you call init_app, you get
While I don't know what the app.record does, there's a call to the self._init_app(app) which register the views:
So basically, for it to works, you have to do the following
Which does make sense somehow as you delay the initialization but can register api views within the views itself at imports time and not only, exclusively in a separate function when you create you app objects. So, it's not really a bug in my opinion but rather a documentation issue :) |
Sorry about this guys. I've updated the documentation to match working behavior: api = Api()
api.add_resource(...)
api.init_app(app) |
Based on the discussion here that sounds like the correct fix so I'm going to go ahead and close this out. If you still feel this isn't fixed, feel free to reopen and we can talk about solutions. |
Regression.
Flask 0.10.1, Flask-RESTful 0.2.11 (from PyPI)
Here: a1d59b7#diff-2d0ae3f4d6c2de850684766cfb7c5a6bR83
The text was updated successfully, but these errors were encountered: