ImportError: cannot import name add_to_builtins under Django 1.9

  • 27 October, 2015

Whilst upgrading various projects to Django 1.9, I found myself repeatedly searching for the following code snippet so I offer it below as a more permanent note for myself and to aid others.

If you used django.template.base.add_to_builtins to avoid tedious and unsightly {% load module %} blocks in your template files, under Django 1.9 you will get the following traceback:

Traceback (most recent call last):
  File "django/core/management/", line 324, in execute
  File "django/", line 18, in setup
  File "django/apps/", line 108, in populate
  File "django/apps/", line 202, in import_models
    self.models_module = import_module(models_module_name)
  File "/usr/lib/python2.7/importlib/", line 37, in import_module
  File "myproject/myproject/utils/", line 1, in <module>
    from django.template.base import add_to_builtins
ImportError: cannot import name add_to_builtins

The solution is to move to defining settings.TEMPLATES instead of calling add_to_builtins. This replaces a number of your existing settings, including TEMPLATE_CONTEXT_PROCESSORS, TEMPLATE_DIRS, TEMPLATE_LOADERS, etc.

For example:

    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS': [
        os.path.join(BASE_DIR, 'templates'),
    'APP_DIRS': True,
    'OPTIONS': {
        'context_processors': [
        'builtins': [

Simply add the modules you previously loaded with add_to_builtins to the builtins key under OPTIONS.

(You can read more in the release notes for Django 1.9, as well as read about settings.TEMPLATES generally.)