i have a function in views.py , for example something like this :
def get_base_content():
footer = SiteContent.objects.get(pk=1)
return {
"footer" : footer,
}
how can i call this function in my template and use footer variable in it ?
If you want to have this variable shown on all templates, then you need to implement a template context processor.
You just need minimal changes to your code:
Now, add that to a separate file, call it
custom_context.py. In yoursettings.pyadd it to yourTEMPLATE_CONTEXT_PROCESSORSsetting:Now, in your view code you just need to make sure you are using
RequestContext. The easiest way to do that is to use therendershortcut:In
hello.htmlyou’ll have{{ foo }}and{{ footer }}