mirror of
https://github.com/django/django.git
synced 2025-04-12 03:22:21 +00:00
[1.10.x] Refs #25854 -- Completed a RequestContext docs example.
Backport of f8c338ec6a372841559e3134cf4d4329c460f8c7 from master
This commit is contained in:
parent
3342f24ff6
commit
a033b351b5
@ -579,8 +579,8 @@ against ``dict``::
|
||||
|
||||
.. _subclassing-context-requestcontext:
|
||||
|
||||
Subclassing ``Context``: ``RequestContext``
|
||||
-------------------------------------------
|
||||
Using ``RequestContext``
|
||||
------------------------
|
||||
|
||||
.. class:: RequestContext(request, dict_=None, processors=None)
|
||||
|
||||
@ -646,17 +646,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…
x
Reference in New Issue
Block a user