#15835 closed Bug (invalid)
middleware.process_response(): TemplateResponse.render() isn't called
Reported by: | Waldemar Kornewald | Owned by: | nobody |
---|---|---|---|
Component: | Core (Other) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
When you return a TemplateResponse from a middleware's process_response() method the response's render() method isn't called. This causes the following exception: "ContentNotRenderedError: The response content must be rendered before it can be iterated over."
Change History (3)
comment:1 by , 14 years ago
Easy pickings: | unset |
---|---|
Resolution: | → invalid |
Status: | new → closed |
comment:2 by , 14 years ago
I'd argue that this is not well designed, then. Why should we have different behavior in response middleware?
comment:3 by , 14 years ago
I am not sure I understand your point. "template response" and "response" phases happen at different points in the request-response cycle; middlewares obviously get different possibilities at each step.
Anyway, if you want to discuss the general design of Django's middleware, you should propose a better alternative on django-developers.
It think this works as designed.
From http://docs.djangoproject.com/en/dev/ref/template-response/:
<quote>
There are three circumstances under which a TemplateResponse will be rendered:
</quote>
If you are using it in the response middleware, you bypass the third item which usually ensures that the rendering happens. You should call render() on the TemplateResponse object before returning it.