MCPcopy
hub / github.com/pallets/flask / load_app

Method load_app

src/flask/cli.py:333–372  ·  view source on GitHub ↗

Loads the Flask app (if not yet loaded) and returns it. Calling this multiple times will just result in the already loaded app to be returned.

(self)

Source from the content-addressed store, hash-verified

331 self._loaded_app: Flask | None = None
332
333 def load_app(self) -> Flask:
334 """Loads the Flask app (if not yet loaded) and returns it. Calling
335 this multiple times will just result in the already loaded app to
336 be returned.
337 """
338 if self._loaded_app is not None:
339 return self._loaded_app
340 app: Flask | None = None
341 if self.create_app is not None:
342 app = self.create_app()
343 else:
344 if self.app_import_path:
345 path, name = (
346 re.split(r":(?![\\/])", self.app_import_path, maxsplit=1) + [None]
347 )[:2]
348 import_name = prepare_import(path)
349 app = locate_app(import_name, name)
350 else:
351 for path in ("wsgi.py", "app.py"):
352 import_name = prepare_import(path)
353 app = locate_app(import_name, None, raise_if_not_found=False)
354
355 if app is not None:
356 break
357
358 if app is None:
359 raise NoAppException(
360 "Could not locate a Flask application. Use the"
361 " 'flask --app' option, 'FLASK_APP' environment"
362 " variable, or a 'wsgi.py' or 'app.py' file in the"
363 " current directory."
364 )
365
366 if self.set_debug_flag:
367 # Update the app's debug flag through the descriptor so that
368 # other values repopulate as well.
369 app.debug = get_debug_flag()
370
371 self._loaded_app = app
372 return app
373
374
375pass_script_info = click.make_pass_decorator(ScriptInfo, ensure=True)

Callers 6

test_scriptinfoFunction · 0.95
decoratorFunction · 0.80
get_commandMethod · 0.80
list_commandsMethod · 0.80
run_commandFunction · 0.80
checkFunction · 0.80

Calls 5

prepare_importFunction · 0.85
locate_appFunction · 0.85
NoAppExceptionClass · 0.85
get_debug_flagFunction · 0.85
create_appMethod · 0.80

Tested by 2

test_scriptinfoFunction · 0.76
checkFunction · 0.64