Re: Why is RequestContext used in this way?

2013-11-27 Thread Andrew Taylor
Thanks guys this was very helpful


On Friday, 15 November 2013 14:12:50 UTC, Tom Evans wrote:
>
> On Fri, Nov 15, 2013 at 12:59 PM, Andrew Taylor 
>  
> wrote: 
> > 
> > 
> > Hi, 
> > 
> > I've followed some example code which is is follows: 
> > 
> > def index(request): 
> > context = RequestContext(request) 
> > context_dict =  {'boldmessage': "I am from the context"} 
> > return render_to_response('rango/index.html',context_dict, context) 
> > 
> > Here RequestContext only has the first argument filled i.e. request. 
> > 
> > My questions are: 
> > 
> > 1. Is RequestContext(request) being used in a kind of dummy way to suck 
> up the context processors for render_to_response? 
> > 2. What would render_to_response be doing if has both context_dict AND 
> RequestContext had a second argument? 
> > 
> > Sorry if these are stupid questions. I'm new to everything python and 
> Dango, and the kind of person who forgets everything they have ever known 
> when trying to decide which pack of toilet paper to buy in the supermarket. 
> > 
>
> This is explained in the docs: 
>
> If you do not pass in a context, a Context will be created from the 
> dictionary passed in. 
> If you do pass in a context, the contents of the dictionary passed in 
> will be merged in to the context. 
>
>
> https://docs.djangoproject.com/en/1.6/topics/http/shortcuts/#django.shortcuts.render_to_response
>  
>
> Cheers 
>
> Tom 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ffe2be8c-310a-4d9d-80d2-61a56930f159%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Why is RequestContext used in this way?

2013-11-15 Thread Tom Evans
On Fri, Nov 15, 2013 at 12:59 PM, Andrew Taylor  wrote:
>
>
> Hi,
>
> I've followed some example code which is is follows:
>
> def index(request):
> context = RequestContext(request)
> context_dict =  {'boldmessage': "I am from the context"}
> return render_to_response('rango/index.html',context_dict, context)
>
> Here RequestContext only has the first argument filled i.e. request.
>
> My questions are:
>
> 1. Is RequestContext(request) being used in a kind of dummy way to suck up 
> the context processors for render_to_response?
> 2. What would render_to_response be doing if has both context_dict AND 
> RequestContext had a second argument?
>
> Sorry if these are stupid questions. I'm new to everything python and Dango, 
> and the kind of person who forgets everything they have ever known when 
> trying to decide which pack of toilet paper to buy in the supermarket.
>

This is explained in the docs:

If you do not pass in a context, a Context will be created from the
dictionary passed in.
If you do pass in a context, the contents of the dictionary passed in
will be merged in to the context.

https://docs.djangoproject.com/en/1.6/topics/http/shortcuts/#django.shortcuts.render_to_response

Cheers

Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFHbX1K_gQej9-_PXWd7Nsr8UvfZ7OZ-UmpHq9oDH7LfmhuT0Q%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Why is RequestContext used in this way?

2013-11-15 Thread Fred Stluka

Andy,

RequestContext is being passed in so that it become available
to the template, so that it can do things like {% csrf_token %}
which requires access to the session id.

I'm not sure what would happen if a dictionary were passed to
RequestContext as an optional 2nd argument.  I've always
passed the dictionary directly to render_to_response().

--Fred

Fred Stluka -- mailto:f...@bristle.com -- http://bristle.com/~fred/
Bristle Software, Inc -- http://bristle.com -- Glad to be of service!
Open Source: Without walls and fences, we need no Windows or Gates.


On 11/15/13 7:59 AM, Andrew Taylor wrote:


Hi,

I've followed some example code which is is follows:

def index(request):
context = RequestContext(request)
context_dict =  {'boldmessage': "I am from the context"}
return render_to_response('rango/index.html',context_dict, context)

Here RequestContext only has the first argument filled i.e. request.

My questions are:

1. Is RequestContext(request) being used in a kind of dummy way to 
suck up the context processors for render_to_response?
2. What would render_to_response be doing if has both context_dict AND 
RequestContext had a second argument?


Sorry if these are stupid questions. I'm new to everything python and 
Dango, and the kind of person who forgets everything they have ever 
known when trying to decide which pack of toilet paper to buy in the 
supermarket.


Andy

--
You received this message because you are subscribed to the Google 
Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to django-users+unsubscr...@googlegroups.com.

To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9f62f09d-cf92-46e2-893c-17d0a39fe4a5%40googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.


--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/528628C9.5070003%40bristle.com.
For more options, visit https://groups.google.com/groups/opt_out.


Why is RequestContext used in this way?

2013-11-15 Thread Andrew Taylor

Hi,

I've followed some example code which is is follows:

def index(request):
context = RequestContext(request)
context_dict =  {'boldmessage': "I am from the context"}
return render_to_response('rango/index.html',context_dict, context)

Here RequestContext only has the first argument filled i.e. request.

My questions are:

1. Is RequestContext(request) being used in a kind of dummy way to suck up 
the context processors for render_to_response?
2. What would render_to_response be doing if has both context_dict AND 
RequestContext had a second argument?

Sorry if these are stupid questions. I'm new to everything python and 
Dango, and the kind of person who forgets everything they have ever known 
when trying to decide which pack of toilet paper to buy in the supermarket.

Andy

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9f62f09d-cf92-46e2-893c-17d0a39fe4a5%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.