Browse Source

show error if multiple Flask instances are detected

add changelog
pull/2297/head
David Lord 8 years ago
parent
commit
7ecdbcfa2b
No known key found for this signature in database
GPG Key ID: 7A1C87E3F5BC42A8
  1. 3
      CHANGES
  2. 28
      flask/cli.py

3
CHANGES

@ -40,6 +40,8 @@ Major release, unreleased
- Allow IP address as exact session cookie domain. (`#2282`_)
- ``SESSION_COOKIE_DOMAIN`` is set if it is detected through ``SERVER_NAME``.
(`#2282`_)
- Auto-detect 0-argument app factory called ``create_app`` or ``make_app`` from
``FLASK_APP``. (`#2297`_)
.. _#1489: https://github.com/pallets/flask/pull/1489
.. _#1898: https://github.com/pallets/flask/pull/1898
@ -50,6 +52,7 @@ Major release, unreleased
.. _#2256: https://github.com/pallets/flask/pull/2256
.. _#2259: https://github.com/pallets/flask/pull/2259
.. _#2282: https://github.com/pallets/flask/pull/2282
.. _#2297: https://github.com/pallets/flask/pull/2297
Version 0.12.2
--------------

28
flask/cli.py

@ -41,32 +41,42 @@ def find_best_app(module):
return app
# Otherwise find the only object that is a Flask instance.
matches = [v for k, v in iteritems(module.__dict__)
if isinstance(v, Flask)]
matches = [
v for k, v in iteritems(module.__dict__) if isinstance(v, Flask)
]
if len(matches) == 1:
return matches[0]
elif len(matches) > 1:
raise NoAppException(
'Auto-detected multiple Flask applications in module "{module}".'
' Use "FLASK_APP={module}:name" to specify the correct'
' one.'.format(module=module.__name__)
)
# Search for app factory callables.
for attr_name in 'create_app', 'make_app':
app_factory = getattr(module, attr_name, None)
if callable(app_factory):
try:
app = app_factory()
if isinstance(app, Flask):
return app
except TypeError:
raise NoAppException(
'Auto-detected "{callable}()" in module "{module}", but '
'could not call it without specifying arguments.'
.format(callable=attr_name,
module=module.__name__))
'could not call it without specifying arguments.'.format(
callable=attr_name, module=module.__name__
)
)
raise NoAppException(
'Failed to find application in module "{module}". Are you sure '
'it contains a Flask application? Maybe you wrapped it in a WSGI '
'middleware or you are using a factory function.'
.format(module=module.__name__))
'Failed to find application in module "{module}". Are you sure '
'it contains a Flask application? Maybe you wrapped it in a WSGI '
'middleware.'.format(module=module.__name__)
)
def prepare_exec_for_file(filename):

Loading…
Cancel
Save