#24622: Response "context" and "templates" not available in the Test Client when
using Jinja2 - Django 1.8
-------------------------------------+------------------------------------
Reporter: rivantis | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: 1.8
Severity: Normal | Resolution:
Keywords: jinja2, test client | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+------------------------------------
Comment (by prestontimmons):
Thanks for looking into that, Carl.
First, I agree that it would be nice to remove the DTL monkeypatch. We
might be able to do this by adding an `enable_signals` option to the
Django backend. This way signals could be enabled or disabled via the
`TEMPLATES` setting. I'll look into this further to see if I'm missing
anything here. (#14365)
Second, while an `Environment` subclass for Jinja2 is definitely cleaner,
it may be insufficient for the bigger use cases outside this ticket. From
what I can tell, `Environment._load_template` doesn't have access to
context variables. Django uses the same signal to populate
`response.context` and `response.templates`. Context variables are also
used in the Django debug toolbar template panel. I guess we could patch in
the instrumentation at the instance level, here, though. That's not great
but it's an improvement over changing Jinja2 internally.
Also, I suppose any signal here should send an instance of the backend
template class rather than the internal template class. For
`assertTemplateUsed` to work, we need to ensure the signalled template
objects have a `name` attribute.
--
Ticket URL: <https://code.djangoproject.com/ticket/24622#comment:6>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/066.495d58751acfd49b34c5ad63f0ede106%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.