New to Django so sorry if this is trivial
I have a “base.html” template that is extended by a lot of other templates. In this “base.html” template I have a form that is generated from a “forms.Form” derived class called “SearchForm”
.
The question is: Can I import “SearchForm” into the the “base.html” template instead of passing the “Searchform” as a context to every view that is derived from “base.html”
Use Django’s template context processor.
Here’s a simple example:
Then update your
settings.pywithhttps://docs.djangoproject.com/en/dev/ref/settings/#template-context-processors
After this,
{{ form }}will be available on any templates which you render usingrender_to_responsewith aRequestContextpassed in.