Django: What's the use of the context_instance parameter in the render shortcut function? -
documentation on 'render' shortcut
according link above, context_instance parameter defined
the context instance render template with. default, template rendered requestcontext instance (filled values request , dictionary).
with definition in mind, don't see scenarios benefit supplying context_instance argument. mean if need provide additional context values add them dictionary parameter. don't know how context_instance can useful. please educate me. thanks.
the main scenario make variables available in template. example, auth context processor makes (amongst others) user variable available use in template don't have pass yourself. although it's quite big paragraph, django documentation quite job @ explaining it.
in nutshell: adding context_instance=requestcontext(request) render call, processors defined in settings.py (under template_context_processors variable) executed in order. each of these processors return dict variables made available in template. using default set, means not have add e.g. user, csrf or messages variables yourself: done processors.
an example own context processor add main menu parameters template. want highlight menu current category user viewing: creating own context processor determines current location, add variables in template used menu highlighting.
Comments
Post a Comment