Search code examples
django-2.0django-admin-tools

Where can I put template loaders when AppDirs is set to True in Django - Django-admin-tools


I am attempting use a module called django-admin-tools. It requires me to place 'admin_tools.template_loaders.Loader' at the top of my templates. I have AppDirs: True which means that I can't use the 'loaders' option in the options section of templates. Where can I put 'admin_tools.template_loaders.Loader' when AppDirs is set to True?


Solution

  • According this doc, when APP_DIRS is True, that means django just use django.template.loaders.app_directories.Loader.

    So I think you don't have to set APP_DIRS True. Just append that loader in loaders with admin_tools.template_loaders.Loader

    TEMPLATES = [
        {
            'BACKEND': 'django.template.backends.django.DjangoTemplates',
            'DIRS': [],
            'APP_DIRS': False,
            'OPTIONS': {
                ...,
                'loaders': [
                    'django.template.loaders.app_directories.Loader',
                    'admin_tools.template_loaders.Loader',
                    ...
                ],
            },
        },
    ]