mirror of https://github.com/django/django.git
Refs #25854 -- Completed a RequestContext docs example.
This commit is contained in:
parent
518eaf1fa2
commit
f8c338ec6a
|
@ -569,8 +569,8 @@ against ``dict``::
|
||||||
|
|
||||||
.. _subclassing-context-requestcontext:
|
.. _subclassing-context-requestcontext:
|
||||||
|
|
||||||
Subclassing ``Context``: ``RequestContext``
|
Using ``RequestContext``
|
||||||
-------------------------------------------
|
------------------------
|
||||||
|
|
||||||
.. class:: RequestContext(request, dict_=None, processors=None)
|
.. 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::
|
example, the :class:`RequestContext` instance gets a ``ip_address`` variable::
|
||||||
|
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
from django.template import RequestContext
|
from django.template import RequestContext, Template
|
||||||
|
|
||||||
def ip_address_processor(request):
|
def ip_address_processor(request):
|
||||||
return {'ip_address': request.META['REMOTE_ADDR']}
|
return {'ip_address': request.META['REMOTE_ADDR']}
|
||||||
|
|
||||||
def some_view(request):
|
def client_ip_view(request):
|
||||||
# ...
|
template = Template('{{ title }}: {{ ip_address }}')
|
||||||
c = RequestContext(request, {
|
context = RequestContext(request, {
|
||||||
'foo': 'bar',
|
'title': 'Your IP Address',
|
||||||
}, [ip_address_processor])
|
}, [ip_address_processor])
|
||||||
return HttpResponse(t.render(c))
|
return HttpResponse(template.render(context))
|
||||||
|
|
||||||
.. _context-processors:
|
.. _context-processors:
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue