I wanted to define a custom widget SearchBar, which when associated with a CharField, would automatically render a text input box for search, followed by a search button. I created a template html and put it at a custom location. I tried to create a new widget by inheriting from django.forms.widgets.Input
, but when I give template_name=
, it tries to locate the path in django/forms/templates
only, not my custom location myapp/forms/templates
. It looks like this path is baked into django.template.backends.django.DjangoTemplates
. Is there a simpler way than inheriting from DjangoTemplates then adding template paths to achieve what I want?
BTW, I use Bootstrap5, and so also use django-bootstrap5, so I suppose I need to write a renderer for this too.
Would I be better off manually rendering the field and button in every form by hand rather than define a custom widget?
2