Just coming back to Django after an 18 month absense, great to see
some of the work that's gone on here, i'm really impressed! Been using
Rails for a while (not by choice) and it's a joy to get back into
Django.
Enough of the fluffing though, and down to business.
render_to_response is a great shortcut, however in my opinion it's let
down by not supporting request. I see this has been discussed a bit on
the ticket, however that's more in respect to replacing the existing
shortcut.
I propose a new shortcut of the following form:
Index: django/shortcuts/__init__.py
===================================================================
--- django/shortcuts/__init__.py (revision 5526)
+++ django/shortcuts/__init__.py (working copy)
@@ -5,11 +5,16 @@
from django.template import loader
from django.http import HttpResponse, Http404
from django.db.models.manager import Manager
+from django.template.context import RequestContext
def render_to_response(*args, **kwargs):
return HttpResponse(loader.render_to_string(*args, **kwargs))
load_and_render = render_to_response # For backwards compatibility.
+def render_to_response_with_req(request, *args, **kwargs):
+ kwargs['context_instance'] = RequestContext(request)
+ return render_to_response(*args, **kwargs)
+
def get_object_or_404(klass, *args, **kwargs):
if isinstance(klass, Manager):
manager = klass
def get_object_or_404(klass, *args, **kwargs):
if isinstance(klass, Manager):
manager = klass
If anyone has any ideas for better names, please chip in.
Regards,
Paul
Welcome back ;)
> render_to_response is a great shortcut, however in my opinion it's let
> down by not supporting request.
render_to_response(context_instance=RequestContext(request))
Convoluted, and it means having to import RequestContext, but it is
possible.
I agree, an official shortcut would be good. This comes up at least
daily on IRC, with the usual response being http://www.djangosnippets.org/snippets/3/
Isn't this just the 'direct_to_template' generic view?
Yours,
Russ Magee %-)
Firstly, you should be `return`ing this request. ;)
Secondly, it looks like the direct_to_template function does exactly
this (albeit with a tiny bit of overhead in checking for and calling
callable context items).