mirror of
https://github.com/django/django.git
synced 2025-08-03 18:38:50 +00:00
Add missing imports and models to the examples in the template layer documentation
This commit is contained in:
parent
a7e2835276
commit
7264e5c661
2 changed files with 39 additions and 14 deletions
|
@ -286,6 +286,7 @@ fully-populated dictionary to ``Context()``. But you can add and delete items
|
|||
from a ``Context`` object once it's been instantiated, too, using standard
|
||||
dictionary syntax::
|
||||
|
||||
>>> from django.template import Context
|
||||
>>> c = Context({"foo": "bar"})
|
||||
>>> c['foo']
|
||||
'bar'
|
||||
|
@ -397,6 +398,9 @@ Also, you can give ``RequestContext`` a list of additional processors, using the
|
|||
optional, third positional argument, ``processors``. In this example, the
|
||||
``RequestContext`` instance gets a ``ip_address`` variable::
|
||||
|
||||
from django.http import HttpResponse
|
||||
from django.template import RequestContext
|
||||
|
||||
def ip_address_processor(request):
|
||||
return {'ip_address': request.META['REMOTE_ADDR']}
|
||||
|
||||
|
@ -417,6 +421,9 @@ optional, third positional argument, ``processors``. In this example, the
|
|||
:func:`~django.shortcuts.render_to_response()`: a ``RequestContext``
|
||||
instance. Your code might look like this::
|
||||
|
||||
from django.shortcuts import render_to_response
|
||||
from django.template import RequestContext
|
||||
|
||||
def some_view(request):
|
||||
# ...
|
||||
return render_to_response('my_template.html',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue