Skip to content
Myr

Subscribe to signals with extra kwargs in the docs

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Armin Ronacher · committed by Armin Ronacher · parent ebd7468 · Browse files · 1 file+8 added−8 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+8 added−8 removed

  • other:+8 added−8 removed

1 file+8 added−8 removed

modified:docs/signals.rst+8 added-8 removed
84 unmodified lines
85specified that way one has to pass the list in as argument::8687 from flask import template_rendered8889 def captured_templates(app, recorded):89 def captured_templates(app, recorded, **extra):90 def record(sender, template, context):91 recorded.append((template, context))92 return template_rendered.connected_to(record, app)9394The example above would then look like this::9596 templates = []97 with captured_templates(app, templates):97 with captured_templates(app, templates, **extra):98 ...99 template, context = templates[0]100101.. admonition:: Blinker API Changes
59 unmodified lines
161162 from flask import template_rendered163164 @template_rendered.connect_via(app)165 def when_template_rendered(sender, template, context):165 def when_template_rendered(sender, template, context, **extra):166 print 'Template %s is rendered with %s' % (template.name, context)167168Core Signals169------------
10 unmodified lines
180 and the context as dictionary (named `context`).181182 Example subscriber::183184 def log_template_renders(sender, template, context):184 def log_template_renders(sender, template, context, **extra):185 sender.logger.debug('Rendering template "%s" with context %s',186 template.name or 'string template',187 context)188
9 unmodified lines
198 proxies such as :class:`~flask.request`.199200 Example subscriber::201202 def log_request(sender):202 def log_request(sender, **extra):203 sender.logger.debug('Request context is set up')204205 from flask import request_started206 request_started.connect(log_request, app)
5 unmodified lines
212 It is passed the response to be sent named `response`.213214 Example subscriber::215216 def log_response(sender, response):216 def log_response(sender, response, **extra):217 sender.logger.debug('Request context is about to close down. '218 'Response: %s', response)219220 from flask import request_finished
8 unmodified lines
229 itself is passed to the subscriber as `exception`.230231 Example subscriber::232233 def log_exception(sender, exception):233 def log_exception(sender, exception, **extra):234 sender.logger.debug('Got exception during processing: %s', exception)235236 from flask import got_request_exception237 got_request_exception.connect(log_exception, app)
7 unmodified lines
245 is not something you can rely on.246247 Example subscriber::248249 def close_db_connection(sender):249 def close_db_connection(sender, **extra):250 session.close()251252 from flask import request_tearing_down253 request_tearing_down.connect(close_db_connection, app)
2 unmodified lines