On Mon, Nov 29, 2010 at 4:21 AM, Ivan Sagalaev <man...@softwaremaniacs.org> wrote: > On 11/28/2010 10:13 AM, Russell Keith-Magee wrote: >> >> For your consideration, I present a patch to resolve #12815 and >> #12816, adding a TemplateResponse and a render() shortcut. > > Thank you! > >> - The render() shortcut doesn't use TemplateResponse. Since render() >> and TemplateReponse() have exactly the same prototype, I didn't see >> the value in adding a shortcut that just redirected to a different >> constructor. However, there is still value in making an easy-to-use >> render_to_response, for those situations where a TemplateResponse >> can't be used. > > I have a slight (about -0) concern about this… It might turned out as the > same mistake that was made with render_to_response() in the first place: it > wasn't powerful enough (i.e. it didn't use RequestContext) to be used as a > default shortcut. If people would like TemplateResponse they would be > frustrated that render() doesn't use it. Using TemplateResponse directly is > perfectly possible but then we have to explain to every newcomer why are > there two slightly different ways of doing one thing. I think that cases > where one wants to care about using pure HttpResponse instead of > TemplateResponse would be rare and it's better not be the default behavior.
My counterargument would be this -- if you use TemplateResponse, there's no need to use a shortcut at all. Unlike HttpResponse, you don't need to construct a context, load a template and render it. The constructor for TemplateResponse is all you need. This is born out by the fact that the TemplateReponse shortcut isn't even a method definition -- it's a rename: render = TemplateResponse I don't see the point in just putting a rename into shortcuts; so we might as well use the shortcut for something that might be useful -- such as providing a way to easily use ResponseContext on normal HttpResponses. > P.S. Noticed a typo in the patch: > > @@ -164,6 +154,13 @@ > urlresolvers.set_urlconf(None) > > try: > + # Apply template response middleware and the bake the response > + # if the response can be baked > + if hasattr(response, 'bake') and callable(response.bake): > > The first line of the comment should be "and the*n* bake the response". Thanks - I've fixed this in my copy. Yours, Russ Magee %-) -- You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-develop...@googlegroups.com. To unsubscribe from this group, send email to django-developers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.