On Tue, Jan 5, 2010 at 9:23 PM, Ivan Sagalaev
<man...@softwaremaniacs.org> wrote:
> Russell Keith-Magee wrote:
>> I'm in complete agreement with Simon on this point. I fail to see the
>> benefit of decorators in this context.
>
> I can see one valid point that "render_to" guys have. Which is,
> incidentally, has nothing to do with the decorator syntax. An
> HttpResponse with an opaque string as its content is hard to alter after
> it is returned from a view (one of the precedents was the old
> CsrfMiddleware was parsing HTML to inject a token). And most of the real
> use-cases for this are about adding something to the view's context
> before it blends in a template. Right now the only way to do it is with
> context processors but they are global, not per-view, which is not
> convenient.
>
> I think it can be solved another way, by something like a special
> HttpResponse subclass -- TemplateResponse. It can keep a template and
> its context separate until the very last moment when its contents is
> asked and only then do render a template.
>
> This will allow extension of the views:
>
>     # some library:
>
>     def library_view(request):
>         # ...
>         return TemplateReponse('template.html', context = { ... })
>
>     # user code:
>
>     def my_view(request):
>         response = library_view(request)
>         response.context.update({ ... })
>         return response
>
> Russel, can you see something like this in Django trunk?

Certainly - and Simon made exactly this proposal during the review of
the CSRF work. Simon even provided a sample implementation:

http://groups.google.com/group/django-developers/msg/b1b3f8854b9ae2b1

(Ignore the bits about the CSRF implementation - the interesting bits
are near the end of the message)

I haven't taken the temperature of anyone else in the core, but you
can take it as read that Simon and myself are both +1. The sprint this
weekend would be a great opportunity to advocate for inclusion of
this. With a few tests and documentation, Simon's patch could easily
be made trunk-ready.

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.


Reply via email to