Overriding Field Widgets In Django Doesn't Work. Template Not Found. The Solution

May 04, 2018 · Updated: Jul 17, 2021 · by Tim Kamanin

One day you may want to override a default Django form input widget. Let's say; you'll want to tweak a Date widget, so it has type="date" on it.

So you'd go out and do the regular drill:

  1. Find the source file inside the Django dir: forms/templates/django/forms/widgets/input.html;

  2. Copy and save its contents into your project's main templates directory as templates/django/forms/widgets/date.html;

  3. Tweak the source and make it look like:

    <input type="date" name="{{ }}"{% if widget.value != None %}
        value="{{ widget.value|stringformat:'s' }}"{% endif %}{% include
        "django/forms/widgets/attrs.html" %} />

  4. Restart the server and expect all Date fields now be natively supported by Chrome browser.

But in the end, it won't work.

You can keep hitting the refresh button as many times as you want but it won't work until you do the following steps:

  1. Add 'django.forms' to your INSTALLED_APPS;

  2. Add FORM_RENDERER = 'django.forms.renderers.TemplatesSetting' to your

Why is that? Well it's a little low-level Django quirk you can read about in the docs here:

Which means, if you want to override default widget templates, you need to explicitly register 'django.forms' as an app and specify your FORM_RENDERER as 'django.forms.renderers.TemplatesSetting'.

I hope this saves you some time, my friend.

Hey, if you've found this useful, please share the post to help other folks find it:

There's even more:

Subscribe for updates

  • via Twitter: @timonweb
  • old school RSS:
  • or evergreen email ↓ ↓ ↓