Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
Ticket #650 - render_to_response uses Context instead DjangoContext
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Paul Bowsher  
View profile  
 More options Jun 25 2007, 6:45 pm
From: Paul Bowsher <paul.bows...@gmail.com>
Date: Mon, 25 Jun 2007 22:45:21 -0000
Local: Mon, Jun 25 2007 6:45 pm
Subject: Ticket #650 - render_to_response uses Context instead DjangoContext
Hi all,

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "Ticket #650 - render_to_response uses Context instead RequestContext" by SmileyChris
SmileyChris  
View profile  
 More options Jun 25 2007, 10:45 pm
From: SmileyChris <smileych...@gmail.com>
Date: Tue, 26 Jun 2007 02:45:54 -0000
Local: Mon, Jun 25 2007 10:45 pm
Subject: Re: Ticket #650 - render_to_response uses Context instead RequestContext
On Jun 26, 10:45 am, Paul Bowsher <paul.bows...@gmail.com> wrote:

> Hi all,

> Been using
> Rails for a while (not by choice) and it's a joy to get back into
> Django.

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/


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "Ticket #650 - render_to_response uses Context instead DjangoContext" by Russell Keith-Magee
Russell Keith-Magee  
View profile  
 More options Jun 26 2007, 11:51 pm
From: "Russell Keith-Magee" <freakboy3...@gmail.com>
Date: Wed, 27 Jun 2007 11:51:34 +0800
Local: Tues, Jun 26 2007 11:51 pm
Subject: Re: Ticket #650 - render_to_response uses Context instead DjangoContext
On 6/26/07, Paul Bowsher <paul.bows...@gmail.com> wrote:

> 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.

Isn't this just the 'direct_to_template' generic view?

Yours,
Russ Magee %-)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Paul Bowsher  
View profile  
 More options Jun 27 2007, 4:46 am
From: "Paul Bowsher" <paul.bows...@gmail.com>
Date: Wed, 27 Jun 2007 09:46:56 +0100
Local: Wed, Jun 27 2007 4:46 am
Subject: Re: Ticket #650 - render_to_response uses Context instead DjangoContext

No, this is meant to go at the end of a long view function
def index(request):
    # Lots of code
    render_to_response_with_req(request, 'home/index.html', {'a': 'dict'})

etc.

On 6/27/07, Russell Keith-Magee <freakboy3...@gmail.com> wrote:

--
Paul Bowsher

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
SmileyChris  
View profile  
 More options Jun 27 2007, 5:24 am
From: SmileyChris <smileych...@gmail.com>
Date: Wed, 27 Jun 2007 09:24:37 -0000
Local: Wed, Jun 27 2007 5:24 am
Subject: Re: Ticket #650 - render_to_response uses Context instead DjangoContext
On Jun 27, 8:46 pm, "Paul Bowsher" <paul.bows...@gmail.com> wrote:

> No, this is meant to go at the end of a long view function
> def index(request):
>     # Lots of code
>     render_to_response_with_req(request, 'home/index.html', {'a': 'dict'})

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).


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Paul Bowsher  
View profile  
 More options Jun 27 2007, 7:54 am
From: "Paul Bowsher" <paul.bows...@gmail.com>
Date: Wed, 27 Jun 2007 12:54:03 +0100
Local: Wed, Jun 27 2007 7:54 am
Subject: Re: Ticket #650 - render_to_response uses Context instead DjangoContext

Yes, sorry, I missed the return, was hastily typed as an example. Hadn't
seen direct_to_template, that does indeed seem like a good way to go. Thanks
for the pointer :)

On 6/27/07, SmileyChris <smileych...@gmail.com> wrote:

--
Paul Bowsher

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »