Django include the same variables in all views -
i want include same variables in views , avoid repeating , i've been looking @ django docs , found generic display views , tried doesnt seems work. idea how ?
write template context processor:
def add_foo(request): return {'var': 'foo'} save file, lets custom_context.py, put inside same directory views.py.
then, add template_context_processors setting - make sure keep default ones, otherwise other functions may not work. need add python path, add yourapp.custom_context.add_foo,
now, whenever return requestcontext instance (you can using render shortcut, , class based views automatically return requestcontext instance); variable var available in templates, {{ var }}.
Comments
Post a Comment