do you have this in your settings.py:
TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.request',
...
--
regards
KG
http://lawgon.livejournal.com
Coimbatore LUG rox
http://ilugcbe.techstud.org/
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
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.
--
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
Looks exactly like the example from [1], apart from using
render_to_response shortcut rather than manually rendering the
template.
Cheers
Tom
[1] https://docs.djangoproject.com/en/dev/ref/templates/api/#subclassing-context-requestcontext
--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/7f4f7a9f-cf9a-4bf1-9d63-d2b711a58f68%40googlegroups.com.
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/b4MdWpPYEW4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAJrG93CSfhQwNJ1Lv7XQJcKu%3D-ai8fAwtQv2fRDkQ4X9j9ACfA%40mail.gmail.com.