Auto-detect create_app and make_app factory functions
This commit is contained in:
parent
b11f7354d1
commit
ced719ea18
2 changed files with 49 additions and 0 deletions
15
flask/cli.py
15
flask/cli.py
|
|
@ -46,6 +46,21 @@ def find_best_app(module):
|
|||
|
||||
if len(matches) == 1:
|
||||
return matches[0]
|
||||
|
||||
# Search for app factory callables.
|
||||
for attr_name in 'create_app', 'make_app':
|
||||
app_factory = getattr(module, attr_name, None)
|
||||
if app_factory is not None and callable(app_factory):
|
||||
try:
|
||||
app = app_factory()
|
||||
if app is not None and isinstance(app, Flask):
|
||||
return app
|
||||
except TypeError:
|
||||
raise NoAppException('Auto-detected "%s()" in module "%s", '
|
||||
'but could not call it without '
|
||||
'specifying arguments.'
|
||||
% (attr_name, module.__name__))
|
||||
|
||||
raise NoAppException('Failed to find application in module "%s". Are '
|
||||
'you sure it contains a Flask application? Maybe '
|
||||
'you wrapped it in a WSGI middleware or you are '
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue