Flask Connecting to signals


Example

Use a signal's connect method to connect a function to a signal. When a signal is sent, each connected function is called with the sender and any named arguments the signal provides.

from flask import template_rendered

def log_template(sender, template, context, **kwargs):
    sender.logger.info(
        'Rendered template %(template)r with context %(context)r.',
        template=template, context=context
    )

template_rendered.connect(log_template)

See the documentation on built-in signals for information about what arguments they provides. A useful pattern is adding a **kwargs argument to catch any unexpected arguments.