Refs #25854 -- Completed a RequestContext docs example.

This commit is contained in:
Tim Graham 2016-08-18 19:37:07 -04:00
parent 518eaf1fa2
commit f8c338ec6a
1 changed files with 8 additions and 8 deletions

View File

@ -569,8 +569,8 @@ against ``dict``::
.. _subclassing-context-requestcontext:
Subclassing ``Context``: ``RequestContext``
-------------------------------------------
Using ``RequestContext``
------------------------
.. class:: RequestContext(request, dict_=None, processors=None)
@ -636,17 +636,17 @@ using the optional, third positional argument, ``processors``. In this
example, the :class:`RequestContext` instance gets a ``ip_address`` variable::
from django.http import HttpResponse
from django.template import RequestContext
from django.template import RequestContext, Template
def ip_address_processor(request):
return {'ip_address': request.META['REMOTE_ADDR']}
def some_view(request):
# ...
c = RequestContext(request, {
'foo': 'bar',
def client_ip_view(request):
template = Template('{{ title }}: {{ ip_address }}')
context = RequestContext(request, {
'title': 'Your IP Address',
}, [ip_address_processor])
return HttpResponse(t.render(c))
return HttpResponse(template.render(context))
.. _context-processors: