module documentation

Undocumented

Class ​App​Group This works similar to a regular click ~click.Group but it changes the behavior of the command decorator so that it automatically wraps the functions in with_appcontext.
Class ​Flask​Group No summary
Class ​Script​Info No summary
Function load​_dotenv Load "dotenv" files in order of precedence to set environment variables.
Function with​_appcontext No summary
Variable cli Undocumented
Variable dotenv Undocumented
Variable pass​_script​_info Undocumented
Variable ssl Undocumented
Variable version​_option Undocumented
Class ​Cert​Param​Type Click option type for the --cert option. Allows either an existing file, the string 'adhoc', or an import for a ~ssl.SSLContext object.
Class ​Dispatching​App No summary
Class ​No​App​Exception Raised if an application cannot be found or loaded.
Class ​Separated​Path​Type Click option type that accepts a list of values separated by the OS's path separator (:, ; on Windows). Each value is validated as a click.Path type.
Function ​_called​_with​_wrong​_args Check whether calling a function raised a TypeError because the call failed or because something in the factory raised the error.
Function ​_path​_is​_ancestor Take other and remove the length of path from it. Then join it to path. If it is the original value, path is an ancestor of other.
Function ​_validate​_key The --key option must be specified when --cert is a file. Modifies the cert param to be a (cert, key) pair if needed.
Function call​_factory Takes an app factory, a ``script_info` object and optionally a tuple of arguments. Checks for the existence of a script_info argument and calls the app_factory depending on that and the arguments provided.
Function find​_app​_by​_string Check if the given string is a variable name or a function. Call a function to get the app instance, or return the variable directly.
Function find​_best​_app Given a module instance this tries to find the best possible application in the module or raises an exception.
Function get​_version Undocumented
Function locate​_app Undocumented
Function main Undocumented
Function prepare​_import Given a filename this will try to calculate the python path, add it to the search path and return the actual module name that is expected.
Function routes​_command Show all registered routes with endpoints and methods.
Function run​_command Run a local development server.
Function shell​_command Run an interactive Python shell in the context of a given Flask application. The application will populate the default namespace of this shell according to its configuration.
Function show​_server​_banner Show extra startup messages the first time the server is run, ignoring the reloader.
def load_dotenv(path=None):

Load "dotenv" files in order of precedence to set environment variables.

If an env var is already set it is not overwritten, so earlier files in the list are preferred over later files.

This is a no-op if python-dotenv is not installed.

Changed in version 1.1.0: Returns False when python-dotenv is not installed, or when the given path isn't a file.
Changed in version 2.0: When loading the env files, set the default encoding to UTF-8.
New in version 1.0.
Parameters
pathLoad the file at this location instead of searching.
Returns
True if a file was loaded.
def with_appcontext(f):
Wraps a callback so that it's guaranteed to be executed with the script's application context. If callbacks are registered directly to the app.cli object then they are wrapped with this function by default unless it's disabled.
cli =

Undocumented

dotenv =

Undocumented

pass_script_info =

Undocumented

ssl =

Undocumented

version_option =

Undocumented

def _called_with_wrong_args(f):
Check whether calling a function raised a TypeError because the call failed or because something in the factory raised the error.
Parameters
fThe function that was called.
Returns
True if the call failed.
def _path_is_ancestor(path, other):
Take other and remove the length of path from it. Then join it to path. If it is the original value, path is an ancestor of other.
def _validate_key(ctx, param, value):
The --key option must be specified when --cert is a file. Modifies the cert param to be a (cert, key) pair if needed.
def call_factory(script_info, app_factory, args=None, kwargs=None):
Takes an app factory, a ``script_info` object and optionally a tuple of arguments. Checks for the existence of a script_info argument and calls the app_factory depending on that and the arguments provided.
def find_app_by_string(script_info, module, app_name):
Check if the given string is a variable name or a function. Call a function to get the app instance, or return the variable directly.
def find_best_app(script_info, module):
Given a module instance this tries to find the best possible application in the module or raises an exception.
def get_version(ctx, param, value):

Undocumented

def locate_app(script_info, module_name, app_name, raise_if_not_found=True):

Undocumented

def main():

Undocumented

def prepare_import(path):
Given a filename this will try to calculate the python path, add it to the search path and return the actual module name that is expected.
@click.command('routes', short_help='Show the routes for the app.')
@click.option('--sort', '-s', type=click.Choice(('endpoint', 'methods', 'rule', 'match')), default='endpoint', help='Method to sort routes by. "match" is the order that Flask will match routes when dispatching a request.')
@click.option('--all-methods', is_flag=True, help='Show HEAD and OPTIONS methods.')
@with_appcontext
def routes_command(sort, all_methods):
Show all registered routes with endpoints and methods.
Parameters
sort:strUndocumented
all​_methods:boolUndocumented
@click.command('run', short_help='Run a development server.')
@click.option('--host', '-h', default='127.0.0.1', help='The interface to bind to.')
@click.option('--port', '-p', default=5000, help='The port to bind to.')
@click.option('--cert', type=CertParamType(), help='Specify a certificate file to use HTTPS.')
@click.option('--key', type=click.Path(exists=True, dir_okay=False, resolve_path=True), callback=_validate_key, expose_value=False, help='The key file to use when specifying a certificate.')
@click.option('--reload/--no-reload', default=None, help='Enable or disable the reloader. By default the reloader is active if debug is enabled.')
@click.option('--debugger/--no-debugger', default=None, help='Enable or disable the debugger. By default the debugger is active if debug is enabled.')
@click.option('--eager-loading/--lazy-loading', default=None, help='Enable or disable eager loading. By default eager loading is enabled if the reloader is disabled.')
@click.option('--with-threads/--without-threads', default=True, help='Enable or disable multithreading.')
@click.option('--extra-files', default=None, type=SeparatedPathType(), help=f"""Extra files that trigger a reload on change. Multiple paths are separated by {os.path.pathsep!r}.""")
@pass_script_info
def run_command(info, host, port, reload, debugger, eager_loading, with_threads, cert, extra_files):

Run a local development server.

This server is for development purposes only. It does not provide the stability, security, or performance of production WSGI servers.

The reloader and debugger are enabled by default if FLASK_ENV=development or FLASK_DEBUG=1.

@click.command('shell', short_help='Run a shell in the app context.')
@with_appcontext
def shell_command():

Run an interactive Python shell in the context of a given Flask application. The application will populate the default namespace of this shell according to its configuration.

This is useful for executing small snippets of management code without having to manually configure the application.

def show_server_banner(env, debug, app_import_path, eager_loading):
Show extra startup messages the first time the server is run, ignoring the reloader.