On Jan 2, 5:52 pm, Simon Willison <si...@simonwillison.net> wrote: > On Dec 30 2009, 10:28 pm, Wim Feijen <wimfei...@gmail.com> wrote: > > > In the discussions on CSRF there have been several proposals to > > include RequestContext by default in render_to_response or in a > > similar function. As a side note to my previous post, I'd like to > > mention my favorite way to do this: render_to , see: > > >http://www.djangosnippets.org/snippets/821/ > > So here's how that's supposed to work: > > @render_to('my/template.html') > def my_view(request, param): > return {'data': 'some_data'} > > I have to admit I don't understand the appeal of this syntax at all. > How is it any better than this? : > > def my_view(request, param): > return render('my/template.html', {'data': 'some_data'}) > > The decorator implementation is more complicated, makes debugging > trickier (since decorators confuse stack traces and other debugging > tools) and doesn't save any typing. What are the advantages? > > I'm a big fan of decorators for things like caching/memoization, but I > don't understand why they provide any advantage for the above. I'm not > a fan of the current @permalink decorator in Django for the same > reason - if a decorator simply changes the syntax for how arguments > are passed to a function, what's the point of using them? > > Cheers, > > Simon
I much prefer the @render_to() syntax. This way, I can think of my view functions as "context variable creators", instead of "response returners". I think of view functions as a sort of context processor thats only meant for one specific template. Almost every single view I have ever written (more or less) follows this pattern: process stuff into variables -> add said variables to a ContextRequest -> send said ContextRequest to a template for rendering. With @render_to, it allows me to delegate all the rendering crap to the decorator, while the view function gets to focus on what is really there for; creating extra variables to be passed on to the template. It makes things simpler for me and adds readability. Also, I've never had a problem with the decorator messing up tracebacks. -- 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.