This adds a helper to grab a template's context. Using a helper from the Flask documentation: http://flask.pocoo.org/docs/1.0/signals/?highlight=template_rendered#subscribing-to-signals
17 lines
376 B
Python
17 lines
376 B
Python
from flask import template_rendered
|
|
from contextlib import contextmanager
|
|
|
|
|
|
@contextmanager
|
|
def captured_templates(app):
|
|
recorded = []
|
|
|
|
def record(sender, template, context, **extra):
|
|
recorded.append((template, context))
|
|
|
|
template_rendered.connect(record, app)
|
|
try:
|
|
yield recorded
|
|
finally:
|
|
template_rendered.disconnect(record, app)
|