mirror of
https://github.com/django/django.git
synced 2024-11-28 10:48:32 +01:00
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``
|
||||
-------------------------------------------
|
||||
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:
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user