Skip to content

Commit

Permalink
Clarified how extra_context values are evaluated and, in particular, …
Browse files Browse the repository at this point in the history
…how to

pass in a "live" QuerySet. Thanks to Jay Parlar for pointing out the potential
for confusion.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@2931 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
malcolmt committed May 17, 2006
1 parent 93201c8 commit eb707d8
Showing 1 changed file with 88 additions and 44 deletions.
132 changes: 88 additions & 44 deletions docs/generic_views.txt
Expand Up @@ -160,10 +160,14 @@ a date in the *future* are not included.
* ``template_loader``: The template loader to use when loading the * ``template_loader``: The template loader to use when loading the
template. By default, it's ``django.template.loader``. template. By default, it's ``django.template.loader``.


* ``extra_context``: A dictionary of values to add to the template context. * ``extra_context``: A dictionary of values to add to the template
If a value in the dictionary is callable, the generic view will call it context. By default, this is an empty dictionary. If a value in the
just before rendering the template. By default, this is an empty dictionary is callable, the generic view will call it
dictionary. just before rendering the template. If it is not callable, it will be
evaluated once, at import time. Note that QuerySets are not callable, so
if you want to pass in a QuerySet in ``extra_context`` and have it
evaluated at render time, you need to wrap it in a function (that
returns the QuerySet).


* ``allow_empty``: A boolean specifying whether to display the page if no * ``allow_empty``: A boolean specifying whether to display the page if no
objects are available. If this is ``False`` and no objects are available, objects are available. If this is ``False`` and no objects are available,
Expand Down Expand Up @@ -225,10 +229,14 @@ with a date in the *future* are not displayed.
* ``template_loader``: The template loader to use when loading the * ``template_loader``: The template loader to use when loading the
template. By default, it's ``django.template.loader``. template. By default, it's ``django.template.loader``.


* ``extra_context``: A dictionary of values to add to the template context. * ``extra_context``: A dictionary of values to add to the template
If a value in the dictionary is callable, the generic view will call it context. By default, this is an empty dictionary. If a value in the
just before rendering the template. By default, this is an empty dictionary is callable, the generic view will call it
dictionary. just before rendering the template. If it is not callable, it will be
evaluated once, at import time. Note that QuerySets are not callable, so
if you want to pass in a QuerySet in ``extra_context`` and have it
evaluated at render time, you need to wrap it in a function (that
returns the QuerySet).


* ``allow_empty``: A boolean specifying whether to display the page if no * ``allow_empty``: A boolean specifying whether to display the page if no
objects are available. If this is ``False`` and no objects are available, objects are available. If this is ``False`` and no objects are available,
Expand Down Expand Up @@ -287,10 +295,14 @@ date in the *future* are not displayed.
* ``template_loader``: The template loader to use when loading the * ``template_loader``: The template loader to use when loading the
template. By default, it's ``django.template.loader``. template. By default, it's ``django.template.loader``.


* ``extra_context``: A dictionary of values to add to the template context. * ``extra_context``: A dictionary of values to add to the template
If a value in the dictionary is callable, the generic view will call it context. By default, this is an empty dictionary. If a value in the
just before rendering the template. By default, this is an empty dictionary is callable, the generic view will call it
dictionary. just before rendering the template. If it is not callable, it will be
evaluated once, at import time. Note that QuerySets are not callable, so
if you want to pass in a QuerySet in ``extra_context`` and have it
evaluated at render time, you need to wrap it in a function (that
returns the QuerySet).


* ``allow_empty``: A boolean specifying whether to display the page if no * ``allow_empty``: A boolean specifying whether to display the page if no
objects are available. If this is ``False`` and no objects are available, objects are available. If this is ``False`` and no objects are available,
Expand Down Expand Up @@ -360,10 +372,14 @@ in the *future* are not displayed.
* ``template_loader``: The template loader to use when loading the * ``template_loader``: The template loader to use when loading the
template. By default, it's ``django.template.loader``. template. By default, it's ``django.template.loader``.


* ``extra_context``: A dictionary of values to add to the template context. * ``extra_context``: A dictionary of values to add to the template
If a value in the dictionary is callable, the generic view will call it context. By default, this is an empty dictionary. If a value in the
just before rendering the template. By default, this is an empty dictionary is callable, the generic view will call it
dictionary. just before rendering the template. If it is not callable, it will be
evaluated once, at import time. Note that QuerySets are not callable, so
if you want to pass in a QuerySet in ``extra_context`` and have it
evaluated at render time, you need to wrap it in a function (that
returns the QuerySet).


* ``allow_empty``: A boolean specifying whether to display the page if no * ``allow_empty``: A boolean specifying whether to display the page if no
objects are available. If this is ``False`` and no objects are available, objects are available. If this is ``False`` and no objects are available,
Expand Down Expand Up @@ -436,10 +452,14 @@ a 404 error, regardless of whether any objects exist for future days.
* ``template_loader``: The template loader to use when loading the * ``template_loader``: The template loader to use when loading the
template. By default, it's ``django.template.loader``. template. By default, it's ``django.template.loader``.


* ``extra_context``: A dictionary of values to add to the template context. * ``extra_context``: A dictionary of values to add to the template
If a value in the dictionary is callable, the generic view will call it context. By default, this is an empty dictionary. If a value in the
just before rendering the template. By default, this is an empty dictionary is callable, the generic view will call it
dictionary. just before rendering the template. If it is not callable, it will be
evaluated once, at import time. Note that QuerySets are not callable, so
if you want to pass in a QuerySet in ``extra_context`` and have it
evaluated at render time, you need to wrap it in a function (that
returns the QuerySet).


* ``allow_empty``: A boolean specifying whether to display the page if no * ``allow_empty``: A boolean specifying whether to display the page if no
objects are available. If this is ``False`` and no objects are available, objects are available. If this is ``False`` and no objects are available,
Expand Down Expand Up @@ -543,10 +563,14 @@ A page representing an individual object.
* ``template_loader``: The template loader to use when loading the * ``template_loader``: The template loader to use when loading the
template. By default, it's ``django.template.loader``. template. By default, it's ``django.template.loader``.


* ``extra_context``: A dictionary of values to add to the template context. * ``extra_context``: A dictionary of values to add to the template
If a value in the dictionary is callable, the generic view will call it context. By default, this is an empty dictionary. If a value in the
just before rendering the template. By default, this is an empty dictionary is callable, the generic view will call it
dictionary. just before rendering the template. If it is not callable, it will be
evaluated once, at import time. Note that QuerySets are not callable, so
if you want to pass in a QuerySet in ``extra_context`` and have it
evaluated at render time, you need to wrap it in a function (that
returns the QuerySet).


* ``context_processors``: A list of template-context processors to apply to * ``context_processors``: A list of template-context processors to apply to
the view's template. See the `RequestContext docs`_. the view's template. See the `RequestContext docs`_.
Expand Down Expand Up @@ -600,10 +624,14 @@ A page representing a list of objects.
* ``template_loader``: The template loader to use when loading the * ``template_loader``: The template loader to use when loading the
template. By default, it's ``django.template.loader``. template. By default, it's ``django.template.loader``.


* ``extra_context``: A dictionary of values to add to the template context. * ``extra_context``: A dictionary of values to add to the template
If a value in the dictionary is callable, the generic view will call it context. By default, this is an empty dictionary. If a value in the
just before rendering the template. By default, this is an empty dictionary is callable, the generic view will call it
dictionary. just before rendering the template. If it is not callable, it will be
evaluated once, at import time. Note that QuerySets are not callable, so
if you want to pass in a QuerySet in ``extra_context`` and have it
evaluated at render time, you need to wrap it in a function (that
returns the QuerySet).


* ``allow_empty``: A boolean specifying whether to display the page if no * ``allow_empty``: A boolean specifying whether to display the page if no
objects are available. If this is ``False`` and no objects are available, objects are available. If this is ``False`` and no objects are available,
Expand Down Expand Up @@ -697,10 +725,14 @@ A page representing an individual object.
* ``template_loader``: The template loader to use when loading the * ``template_loader``: The template loader to use when loading the
template. By default, it's ``django.template.loader``. template. By default, it's ``django.template.loader``.


* ``extra_context``: A dictionary of values to add to the template context. * ``extra_context``: A dictionary of values to add to the template
If a value in the dictionary is callable, the generic view will call it context. By default, this is an empty dictionary. If a value in the
just before rendering the template. By default, this is an empty dictionary is callable, the generic view will call it
dictionary. just before rendering the template. If it is not callable, it will be
evaluated once, at import time. Note that QuerySets are not callable, so
if you want to pass in a QuerySet in ``extra_context`` and have it
evaluated at render time, you need to wrap it in a function (that
returns the QuerySet).


* ``context_processors``: A list of template-context processors to apply to * ``context_processors``: A list of template-context processors to apply to
the view's template. See the `RequestContext docs`_. the view's template. See the `RequestContext docs`_.
Expand Down Expand Up @@ -764,10 +796,14 @@ automatic manipulators that come with Django models.
* ``template_loader``: The template loader to use when loading the * ``template_loader``: The template loader to use when loading the
template. By default, it's ``django.template.loader``. template. By default, it's ``django.template.loader``.


* ``extra_context``: A dictionary of values to add to the template context. * ``extra_context``: A dictionary of values to add to the template
If a value in the dictionary is callable, the generic view will call it context. By default, this is an empty dictionary. If a value in the
just before rendering the template. By default, this is an empty dictionary is callable, the generic view will call it
dictionary. just before rendering the template. If it is not callable, it will be
evaluated once, at import time. Note that QuerySets are not callable, so
if you want to pass in a QuerySet in ``extra_context`` and have it
evaluated at render time, you need to wrap it in a function (that
returns the QuerySet).


* ``context_processors``: A list of template-context processors to apply to * ``context_processors``: A list of template-context processors to apply to
the view's template. See the `RequestContext docs`_. the view's template. See the `RequestContext docs`_.
Expand Down Expand Up @@ -843,10 +879,14 @@ object. This uses the automatic manipulators that come with Django models.
* ``template_loader``: The template loader to use when loading the * ``template_loader``: The template loader to use when loading the
template. By default, it's ``django.template.loader``. template. By default, it's ``django.template.loader``.


* ``extra_context``: A dictionary of values to add to the template context. * ``extra_context``: A dictionary of values to add to the template
If a value in the dictionary is callable, the generic view will call it context. By default, this is an empty dictionary. If a value in the
just before rendering the template. By default, this is an empty dictionary is callable, the generic view will call it
dictionary. just before rendering the template. If it is not callable, it will be
evaluated once, at import time. Note that QuerySets are not callable, so
if you want to pass in a QuerySet in ``extra_context`` and have it
evaluated at render time, you need to wrap it in a function (that
returns the QuerySet).


* ``context_processors``: A list of template-context processors to apply to * ``context_processors``: A list of template-context processors to apply to
the view's template. See the `RequestContext docs`_. the view's template. See the `RequestContext docs`_.
Expand Down Expand Up @@ -924,10 +964,14 @@ contain a form that POSTs to the same URL.
* ``template_loader``: The template loader to use when loading the * ``template_loader``: The template loader to use when loading the
template. By default, it's ``django.template.loader``. template. By default, it's ``django.template.loader``.


* ``extra_context``: A dictionary of values to add to the template context. * ``extra_context``: A dictionary of values to add to the template
If a value in the dictionary is callable, the generic view will call it context. By default, this is an empty dictionary. If a value in the
just before rendering the template. By default, this is an empty dictionary is callable, the generic view will call it
dictionary. just before rendering the template. If it is not callable, it will be
evaluated once, at import time. Note that QuerySets are not callable, so
if you want to pass in a QuerySet in ``extra_context`` and have it
evaluated at render time, you need to wrap it in a function (that
returns the QuerySet).


* ``context_processors``: A list of template-context processors to apply to * ``context_processors``: A list of template-context processors to apply to
the view's template. See the `RequestContext docs`_. the view's template. See the `RequestContext docs`_.
Expand Down

0 comments on commit eb707d8

Please sign in to comment.