2

I'm writing an app, that uses django-floppyforms. Also, my app provides the default twitter bootstrap skin, so i have customized floppyforms templates im my app to make them bootstrap alike. I put floppyforms/{layouts, rows}/bootstrap into my app's templates directory. But it does not work: django won't use them. So, i don't want to enforce end user to put customized templates into his project, in fact, i want to point django to take my local floppyforms templates when it renders in-app content. I just want to make my app standalone without any unhandy depencies.

UPDATE

Now i'm having the similar troubles with django-admintools-bootstrap and Django 1.5.1. It was added before admin_tools in INSTALLED_APPS, but there's no effect. Also it won't collect static for django-admintools-bootstrap. In other similar projects using this two packages and Django 1.4, all works fine. Also, i've checked the release notes for Django 1.5 for template lookup order changes and found nothing about it.

Community
  • 1
  • 1
night-crawler
  • 1,409
  • 1
  • 26
  • 39

2 Answers2

8

Updated answer:

As of Django 1.8, TEMPLATE_DIRS and TEMPLATE_LOADERS are deprecated and replaced by TEMPLATES.

An example of TEMPLATES can be:

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [
            os.path.join(BASE_DIR, 'templates'),
        ],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
            # 'loaders': [
            #     'django.template.loaders.filesystem.Loader',
            #     'django.template.loaders.app_directories.Loader',
            # ],
            'debug': True,
        },
    },
]

The template lookup order is by dictated by the following:

  • Essentialy the most important place is the loaders option of the OPTIONS. If this is defined, it requires that APP_DIRS is not set and follows any explicit order there.

  • If no loaders, and if any DIRS defined, these have priority as the filesystem loader.

  • If no loaders, and APP_DIRS is defined, these have second priority over DIRS.

The above are not explicitly documented, but can easily be deducted by the existing documentation and maybe after some experiments.

Wtower
  • 18,848
  • 11
  • 103
  • 80
3

If they are not in apps template directory, add absolute path of your templates directories in TEMPLATE_DIRS settings. These directories will be searched in order, so add them in front.

If they are in apps directory, you may want to put 'django.template.loaders.app_directories.Loader' ahead of anyone in TEMPLATE_LOADERS setting.

Also, check how you are using template names while specifying templates. You should use as 'floppyforms/layouts/bootstrap/template1.html'.

More info at template loaders

Rohan
  • 52,392
  • 12
  • 90
  • 87
  • floppyforms templates are in the app template directory, so i moved `'django.template.loaders.app_directories.Loader'` to the top of the `TEMPLATE_LOADERS`. Full path looks like '/templates/floppyforms/layouts/bootstrap.html'. It still does not work. Also, if i put floppyforms templates into the project's template path, loader finds them. – night-crawler Aug 03 '13 at 05:39
  • @lilo.panic, what path do you use to specify template? – Rohan Aug 03 '13 at 05:43
  • I just want to point, that I don't specify any path for floppyforms: when i create an instance of `floppyforms.Form` in a view, `floppyforms` use the custom templates to render it. When i render my *own* view, i use path, i.e. `/themes/default/index.html` – night-crawler Aug 03 '13 at 05:51
  • I had a similar problem where I put my templates in a nested folder inside of templates and Django couldn't find them unless the folder name was in the template name string. – rogueleaderr Jun 30 '15 at 08:18