On Tue, Jul 12, 2011 at 2:07 PM, Tom Evans <tevans...@googlemail.com> wrote:
> 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)

I did this from memory, and omitted the very important first argument
to RequestContext (doh!). It should look like this:

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

Cheers

Tom

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