On Tue, Jul 12, 2011 at 1:41 PM, nicolas HERSOG <n.her...@gmail.com> wrote:
> Hi !
>
> It's very strange, i just found a way to solve my probleme but i don't have
> 'django.core.context_processors.request' in my TEMPLATE_CONTEXT_PROCESSORS.
>
> For solve my problem i added in my views.py :
> from django.shortcuts import render_to_response
>
> this is my previous index views who didn t work :
>
>  def index(request):
>      videos = Video.objects.all()
>      t = loader.get_template('myFront/index.html')
>      c = Context({
>          'datas': datas,
>      })
>      return HttpResponse(t.render(c))
>
> and this is the solving one :
>  def index(request):
>      videos = Video.objects.all()
>      t = loader.get_template('myFront/index.html')
>      c = Context({
>          'datas': datas,
>      })
>
>      return render_to_response('empireFront/index.html', c,
> context_instance=RequestContext(request))
>
> Is a a correct way to do in Django ?
>
> I'ill try your solution too,
>
> Thx :)
>

Programming by permutation is never a good strategy.
render_to_response() takes 4 arguments[1]

render_to_response(template_name[, dictionary][, context_instance][, mimetype])

In your 'working but no idea why' example, you are providing a Context
as the dictionary, which works as contexts are dict-like in their
nature, and a RequestContext (with no values) as the context. The
contents of the supplied dictionary are merged* into the context.

A typical view using RequestContext and render_to_response should look
like this:

def someview(request):
  ctxt = RequestContext({
    'hello': 'world',
  })
  return render_to_response('sometemplate.html', context_instance=ctxt)

It is therefore pointless to provide a Context as the dictionary
parameter, and an empty RequestContext as the context parameter.

Cheers

Tom

[1] 
https://docs.djangoproject.com/en/1.3/topics/http/shortcuts/#render-to-response

* Not really. Contexts actually have a stack of dictionaries, and
works down through the stack to resolve a variable used in a template.
It is easier to think of it as merging them though.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to