Django

Code

Changeset 2949

Show
Ignore:
Timestamp:
05/21/06 07:44:58 (2 years ago)
Author:
mtredinnick
Message:

Improved the advice on using QuerySets? in extra_context based on feedback from
Luke Plant.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/docs/generic_views.txt

    r2931 r2949  
    6363objects. 
    6464 
     65Most views also take an optional ``extra_context`` dictionary that you can use 
     66to pass any auxiliary information you wish to the view. The values in the 
     67``extra_context`` dictionary can be either functions (or other callables) or 
     68other objects. Functions are evaluated just before they are passed to the 
     69template. However, note that QuerySets retrieve and cache their data when they 
     70are first evaluated, so if you want to pass in a QuerySet via 
     71``extra_context`` that is always fresh you need to wrap it in a function or 
     72lambda that returns the QuerySet. 
     73 
    6574.. _database API docs: http://www.djangoproject.com/documentation/db_api/ 
    6675 
     
    162171 
    163172    * ``extra_context``: A dictionary of values to add to the template 
    164       context. By default, this is an empty dictionary. If a value in the 
    165       dictionary is callable, the generic view will call it 
    166       just before rendering the template. If it is not callable, it will be 
    167       evaluated once, at import time. Note that QuerySets are not callable, so 
    168       if you want to pass in a QuerySet in ``extra_context`` and have it 
    169       evaluated at render time, you need to wrap it in a function (that 
    170       returns the QuerySet). 
     173      context. By default, this is an empty dictionary. 
     174      dictionary is callable, the generic view will call it 
     175      just before rendering the template. 
    171176 
    172177    * ``allow_empty``: A boolean specifying whether to display the page if no 
     
    233238      context. By default, this is an empty dictionary. If a value in the 
    234239      dictionary is callable, the generic view will call it 
    235       just before rendering the template. If it is not callable, it will be 
    236       evaluated once, at import time. Note that QuerySets are not callable, so 
    237       if you want to pass in a QuerySet in ``extra_context`` and have it 
    238       evaluated at render time, you need to wrap it in a function (that 
    239       returns the QuerySet). 
     240      just before rendering the template. 
    240241 
    241242    * ``allow_empty``: A boolean specifying whether to display the page if no 
     
    299300      context. By default, this is an empty dictionary. If a value in the 
    300301      dictionary is callable, the generic view will call it 
    301       just before rendering the template. If it is not callable, it will be 
    302       evaluated once, at import time. Note that QuerySets are not callable, so 
    303       if you want to pass in a QuerySet in ``extra_context`` and have it 
    304       evaluated at render time, you need to wrap it in a function (that 
    305       returns the QuerySet). 
     302      just before rendering the template. 
    306303 
    307304    * ``allow_empty``: A boolean specifying whether to display the page if no 
     
    376373      context. By default, this is an empty dictionary. If a value in the 
    377374      dictionary is callable, the generic view will call it 
    378       just before rendering the template. If it is not callable, it will be 
    379       evaluated once, at import time. Note that QuerySets are not callable, so 
    380       if you want to pass in a QuerySet in ``extra_context`` and have it 
    381       evaluated at render time, you need to wrap it in a function (that 
    382       returns the QuerySet). 
     375      just before rendering the template. 
    383376 
    384377    * ``allow_empty``: A boolean specifying whether to display the page if no 
     
    456449      context. By default, this is an empty dictionary. If a value in the 
    457450      dictionary is callable, the generic view will call it 
    458       just before rendering the template. If it is not callable, it will be 
    459       evaluated once, at import time. Note that QuerySets are not callable, so 
    460       if you want to pass in a QuerySet in ``extra_context`` and have it 
    461       evaluated at render time, you need to wrap it in a function (that 
    462       returns the QuerySet). 
     451      just before rendering the template. 
    463452 
    464453    * ``allow_empty``: A boolean specifying whether to display the page if no 
     
    567556      context. By default, this is an empty dictionary. If a value in the 
    568557      dictionary is callable, the generic view will call it 
    569       just before rendering the template. If it is not callable, it will be 
    570       evaluated once, at import time. Note that QuerySets are not callable, so 
    571       if you want to pass in a QuerySet in ``extra_context`` and have it 
    572       evaluated at render time, you need to wrap it in a function (that 
    573       returns the QuerySet). 
     558      just before rendering the template. 
    574559 
    575560    * ``context_processors``: A list of template-context processors to apply to 
     
    628613      context. By default, this is an empty dictionary. If a value in the 
    629614      dictionary is callable, the generic view will call it 
    630       just before rendering the template. If it is not callable, it will be 
    631       evaluated once, at import time. Note that QuerySets are not callable, so 
    632       if you want to pass in a QuerySet in ``extra_context`` and have it 
    633       evaluated at render time, you need to wrap it in a function (that 
    634       returns the QuerySet). 
     615      just before rendering the template. 
    635616 
    636617    * ``allow_empty``: A boolean specifying whether to display the page if no 
     
    729710      context. By default, this is an empty dictionary. If a value in the 
    730711      dictionary is callable, the generic view will call it 
    731       just before rendering the template. If it is not callable, it will be 
    732       evaluated once, at import time. Note that QuerySets are not callable, so 
    733       if you want to pass in a QuerySet in ``extra_context`` and have it 
    734       evaluated at render time, you need to wrap it in a function (that 
    735       returns the QuerySet). 
     712      just before rendering the template. 
    736713 
    737714    * ``context_processors``: A list of template-context processors to apply to 
     
    800777      context. By default, this is an empty dictionary. If a value in the 
    801778      dictionary is callable, the generic view will call it 
    802       just before rendering the template. If it is not callable, it will be 
    803       evaluated once, at import time. Note that QuerySets are not callable, so 
    804       if you want to pass in a QuerySet in ``extra_context`` and have it 
    805       evaluated at render time, you need to wrap it in a function (that 
    806       returns the QuerySet). 
     779      just before rendering the template. 
    807780 
    808781    * ``context_processors``: A list of template-context processors to apply to 
     
    883856      context. By default, this is an empty dictionary. If a value in the 
    884857      dictionary is callable, the generic view will call it 
    885       just before rendering the template. If it is not callable, it will be 
    886       evaluated once, at import time. Note that QuerySets are not callable, so 
    887       if you want to pass in a QuerySet in ``extra_context`` and have it 
    888       evaluated at render time, you need to wrap it in a function (that 
    889       returns the QuerySet). 
     858      just before rendering the template. 
    890859 
    891860    * ``context_processors``: A list of template-context processors to apply to 
     
    968937      context. By default, this is an empty dictionary. If a value in the 
    969938      dictionary is callable, the generic view will call it 
    970       just before rendering the template. If it is not callable, it will be 
    971       evaluated once, at import time. Note that QuerySets are not callable, so 
    972       if you want to pass in a QuerySet in ``extra_context`` and have it 
    973       evaluated at render time, you need to wrap it in a function (that 
    974       returns the QuerySet). 
     939      just before rendering the template. 
    975940 
    976941    * ``context_processors``: A list of template-context processors to apply to