Hi Russell, On Wed, Dec 1, 2010 at 4:03 PM, Russell Keith-Magee <russ...@keith-magee.com> wrote: > On Wed, Dec 1, 2010 at 3:55 PM, Mikhail Korobov <kmik...@googlemail.com> > wrote: >> Just for the record: I'm with Ivan here and think that >> >> from django.template.response import TemplateResponse >> def my_view(request): >> return TemplateResponse(request, 'foo.html') >> >> is worse than >> >> from django.shortcuts import render >> def my_view(request): >> return render(request, 'foo.html') >> >> I think that the cases where user should prefer 'render' returning >> HttpResponse over 'render' returning TemplateResponse are rare so the >> API by itself should suggest TemplateResponse. TemplateResponse is >> more flexible and can provide a performance benefit (the template >> rendering can be prevented in some cases). >> >> I don't see much value in adding 'render' shortcut that just use >> RequestContext after TemplateResponse is introduced - one can still >> use render_to_response if TemplateResponse is undesired and one >> shouldn't use such 'render' in other cases. >> >> 'render' as alias for TemplateResponse seems fine for me: it is a >> shortcut and it adds value by simplifying the API. > > I'd argue it doesn't simplify anything. It saves you a grand total of > 10 characters (plus a couple more on import), but at the cost of the > added complexity of having two ways of doing *exactly* the same thing. > There is also a loss of explicitness -- there's no doubting what > TemplateResponse will return. > > On the other hand, there *is* value in adding a render() shortcut -- > because there will be a subset of cases where a TemplateResponse isn't > needed, but a HttpResponse with a RequestContext is. > > Yours, > Russ Magee %-)
If I got it right, you want to make default shortcut render() that would not use TemplateResponse. But then how one will alter 3rd-party rendered responses in middleware? I suggest people use TemplateResponse by default, and making render = TemplateResponse just to be sure of this, and render_to_response is "just 10 more characters" or a line to make your own render that uses RequestContext. I think, talking about "saving few characters" is not constructive. So I'm talking about good architecture and code beauty. I think your will to make render=render_to_response with RequestContext means you want people to use render_to_response by default. But I'd like if we have a way to make template creators to use TemplateResponse by default. That would encourage better view reusing in django. And that means we would have render=TemplateResponse. However, render_to_response has another feature -- ability to use custom context, and the one real use case is using Context for Http500 when you can't rely on anything. -- Best regards, Yuri V. Baburov, ICQ# 99934676, Skype: yuri.baburov, MSN: bu...@live.com -- 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.