Wednesday, November 27, 2013

Re: Why is RequestContext used in this way?

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 <andyd...@gmail.com> 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+unsubscribe@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.

No comments:

Post a Comment