On Jun 10, 5:44 pm, "Rajeev J Sebastian" <[EMAIL PROTECTED]> wrote: > On Tue, Jun 10, 2008 at 11:20 PM, Gabriel Sean Farrell <[EMAIL PROTECTED]> > wrote: > > > direct_to_template, I'd rather avoid abusing a function by ignoring > > its name and exercising largely undocumented functionality. After > > all, my params aren't going directly to the template. > > Calling a generic view in a function is quite common and in fact an > elegant use of the language. The fact that generic views all use > RequestContext is also widely known. So your patch is not strictly > necessary. it simply adds burden for people learning to use django.
I have nothing against generic views, but the use of direct_to_template is clearly a workaround. Here's an example: def profile_view(request, id): context = {} profile = get_object_or_404(Profile, id=id) context['name'] = profile.firstname + ' ' + profile.lastname return direct_to_template(request, 'profile.html', context) Imagine looking at this as one coming to a new project, or diving into Django code for the first time. It's fairly clear that we're setting up a dictionary of variables for the template, pulling data from the Profile model. But why are we calling direct_to_template when we aren't going directly to the template? Also, the docs [1] don't say anything about the use of direct_to_template in a view, only in urls.py, where its name makes sense. Now let's look at a version with RequestContext: def profile_view(request, id): context = RequestContext(request) profile = get_object_or_404(Profile, id=id) context['name'] = profile.firstname + ' ' + profile.lastname return render_to_response('profile.html', context) I prefer this example to the one using direct_to_template simply because render_to_response better describes what we're doing. To understand it one must understand what the RequestContext object is, however, and since RequestContext can easily be handled by a function in shortcuts, it shouldn't need to be in every view. That's why I think substituting render_response for direct_to_template, as shown in the following example, would actually lighten the burden for users: def profile_view(request, id): context = {} profile = get_object_or_404(Profile, id=id) context['name'] = profile.firstname + ' ' + profile.lastname return render_response(request, 'profile.html', context) There is no universe in which my patch is strictly necessary. It merely makes the expected behavior the default. [1] http://www.djangoproject.com/documentation/generic_views/#django-views-generic-simple-direct-to-template --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-developers?hl=en -~----------~----~----~----~------~----~------~--~---