diff --git a/flask_mongorest/__init__.py b/flask_mongorest/__init__.py index f7da37f2..8450ac9e 100644 --- a/flask_mongorest/__init__.py +++ b/flask_mongorest/__init__.py @@ -1,11 +1,20 @@ -from flask import Blueprint +from flask import Flask, Blueprint from flask_mongorest.methods import Create, BulkUpdate, List class MongoRest(object): - def __init__(self, app, **kwargs): - self.app = app + def __init__(self, app=None, **kwargs): + self.app = None self.url_prefix = kwargs.pop('url_prefix', '') + + if app is not None: + self.init_app(app) + + def init_app(self, app): + if not app or not isinstance(app, Flask): + raise Exception('Invalid Flask application instance') + self.app = app + app.register_blueprint(Blueprint(self.url_prefix, __name__, template_folder='templates')) def register(self, **kwargs):