On Sep 26, 7:44 pm, Alex Gaynor <alex.gay...@gmail.com> wrote:
> So I'm still a little unclear on what this shortcut does that
> direct_to_template doesn't already?

It's a bit less weird. direct_to_template lives somewhere I can't
remember (so I rarely import it), has an argument called
"extra_context" that's actually just the regular context, sets up a
surprising 'params' key in the context dictionary that contains the
function's **kwargs, executes any of the context arguments that are
callables before passing them to the template (even though the
template language usually does that anyway) and has an argument called
mimetype when as-of Django 1.0 content_type is the preferred name for
that parameter [1]. direct_to_template is also an odd name - it makes
sense for a generic view, but it feels strange when you're using it to
render a template from within your view code.

Personally, I want a shortcut called django.shortcuts.render which
looks like this:

def render(request, template, context=None,
content_type=DEFAULT_CONTENT_TYPE):
    return render_to_response(template, context or {},
        context_instance=RequestContext(request),
mimetype=content_type
    )

Much less surprising than direct_to_template, and much easier to
import. I use this in basically every single one of my view functions
so I'd prefer a name that is concise over one that is more
descriptive. That's assuming I can't get any buy-in for my
TemplateResponse concept[2].

Cheers,

Simon

[1] (On further inspection it looks like my attempt to get mimetype
replaced by content_type throughout Django 1.0 was something of an
abject failure, since mimetype is used by both render_to_response and
direct_to_template)
[2] http://github.com/simonw/django-openid/blob/master/django_openid/response.py
- I really like the idea of custom HttpResponse classes that are
lazily evaluated just like QuerySets are, but I've got enough stuff to
evangelise for 1.2 already ;)
--~--~---------~--~----~------------~-------~--~----~
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 
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