Patch is ready for review: http://bitbucket.org/kmike/django/changeset/37d977574923
This is the TempleteResponse by Simon Willison with tests and minor tweaks. Notes: - TemplateResponse and SimpleTemplateResponse reside in django.template.response - django/shortcuts/__init__.py used to have extra spaces. They are removed. - *args and **kwargs in TemplateResponse and SimpleTemplateResponse are gone in order to provide more help for IDEs - 'content' argument is not allowed for TemplateResponse and SimpleTemplateResponse now - context can be omitted now, the only required argument for SimpleTemplateResponse is the template; request and template are required for TemplateResponse - 'response_class' is not implemented but the status code can be passed as 'status' parameter. - _set_content doesn't return a value now The result: from django.shortcuts import render def my_view(request): render(request, 'foo.json', {'foo': 'bar'}, 'application/json', 504) def extended_view(request) response = my_view(request) response.template_context.update({'foo': 'spam', 'baz': 'egg'}) response.template_name = 'spam.json' response.status_code = 400 return response On 21 окт, 23:56, Mikhail Korobov <kmik...@googlemail.com> wrote: > I love programming: two-liner shortcut turns to be a massive core > refactoring ;) Ivan, thank you for the research. > > I'll provide a draft patch for 'render == TemplateResponse' soon. > > By the way, Łukasz Rekucki's suggestion to add the 'response_class' to > render shortcut is complicated much by TemplateResponse because > SimpleTemplateResponse is inherited from HttpResponse. > > On 21 окт, 22:34, Ivan Sagalaev <man...@softwaremaniacs.org> wrote: > > > > > On 10/21/2010 03:22 PM, Ivan Sagalaev wrote: > > > > On 10/21/2010 11:49 AM, Mikhail Korobov wrote: > > >> 2. Does TemplateResponse allow pretty exception pages or not? Is Ben's > > >> issue resolved? > > > > I'll look into it this evening (MSD). > > > So I did. > > > There are actually two problems: > > > - Exceptions in response middleware are indeed happen outside of the > > request's `try .. except` block. This is a problem by itself[1] and I'd > > be happy to fix it after ticket 9886[2] is committed. It's another > > refactoring of core request code so I don't want to mess things up doing > > one patch on top of another :-). > > > - Non-pretty plain text tracebacks can be caused not only be middleware > > but also by any error occurring during template rendering. Because all > > this happen *after* request was returned to the web server handler and > > is being iterated over. > > > This second problem can be easily fixed by introducing a method for > > explicit evaluation of the content: `evaluate()` or `force_content()` > > that will be a noop for any HttpRespone class except the > > TemplateResponse. The method will be called by the request handler right > > before returning the response. > > > Sounds good? > > > P.S. BTW looking at the TemplateResponse implementation I see that Simon > > had actually intended it to be effectively *the* render shortcut[3]. I > > find it quite beautiful really :-) > > > [1]:http://code.djangoproject.com/ticket/14523 > > [2]:http://code.djangoproject.com/ticket/9886 > > [3]:http://github.com/simonw/django-openid/blob/master/django_openid/resp... -- 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.