Cannot find default form templates after upgrading django from 3.x to 4.x

I just upgraded django from 3.x to 4.x. I am getting error for template not found:

TemplateDoesNotExist at /admin/login/
django/forms/errors/list/default.html

The template is in this location:

./lib/python3.8/site-packages/django/forms/templates/django/forms/errors/list/default.html

Django is trying to look in those locations:

django.template.loaders.filesystem.Loader: ./project/templates/django/forms/errors/list/default.html (Source does not exist)
django.template.loaders.app_directories.Loader: ./lib/python3.8/site-packages/django/contrib/admin/templates/django/forms/errors/list/default.html (Source does not exist)
django.template.loaders.app_directories.Loader: ./lib/python3.8/site-packages/django/contrib/auth/templates/django/forms/errors/list/default.html (Source does not exist)
django.template.loaders.app_directories.Loader: ./project/android/templates/django/forms/errors/list/default.html (Source does not exist)
django.template.loaders.app_directories.Loader: ./project/webapp/templates/django/forms/errors/list/default.html (Source does not exist)
django.template.loaders.app_directories.Loader: ./lib/python3.8/site-packages/oauth2_provider/templates/django/forms/errors/list/default.html (Source does not exist)
django.template.loaders.app_directories.Loader: ./lib/python3.8/site-packages/rest_framework/templates/django/forms/errors/list/default.html (Source does not exist)
django.template.loaders.app_directories.Loader: ./lib/python3.8/site-packages/debug_toolbar/templates/django/forms/errors/list/default.html (Source does not exist)
django.template.loaders.app_directories.Loader: ./lib/python3.8/site-packages/ajax_select/templates/django/forms/errors/list/default.html (Source does not exist)

So obviously, django is not even looking into it's own django.forms directory and I cannot figure out why. Is there some new settings on 4.x, that I am missing?

I worked out why these templates aren't found. If 'django.forms' isn't in the INSTALLED_APPS, the template directory isn't found. I've not checked the Django docs, but perhaps this is a side-effect of a tightening of the template search behaviour. The default setup has APP_DIRS: True, but i'm guessing you didn't have that in your TEMPLATES dict like me - as the default setup finds the template ok (ie if viewing the admin)

Here's what worked for me:

DJANGO_APPS = [
    "django.contrib.admin",
    "django.contrib.auth",
    "django.contrib.contenttypes",
    "django.contrib.sessions",
    "django.contrib.sites",
    "django.contrib.messages",
    "django.contrib.staticfiles",
    "django.contrib.humanize",
    "django.forms",
]

NB I use a cookie cutter based template which separates out Django apps from third party and project apps.

Back to Top