JavaCake
JavaCake

Reputation: 4115

Django unable to distinguish between template directory when extending

I have two apps, consisting of adminApp and mobileApp. Both have their own template directory and totally seperated. Unfortunately django keeps looking in the wrong directory when i eg. use extend, it looks into the first template directory according to the order in INSTALLED_APPS:

TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
)

INSTALLED_APPS = (
    ...
    'adminApp',
    'mobileApp',
    ...
)

My directory structure is:

adminApp/
    templates/
        base.html

mobileApp/
    templates/
        base.html

So basically what happens is that when i have a file such as mobileApp/templates/pages/index.html with a {% extends "base.html" %} it uses adminApp/templates/base.html instead of its own.

How can i avoid this and keep them separated?

Upvotes: 1

Views: 57

Answers (1)

Simeon Visser
Simeon Visser

Reputation: 122376

Your apps don't follow the Django conventions for template directories. The app name should be repeated to avoid this issue:

adminApp/
    templates/
        adminApp/
            base.html

mobileApp/
    templates/
        mobileApp/
            base.html

You can then unambiguously specify which template you wish to extend:

{% extends "mobileApp/base.html" %}

Upvotes: 1

Related Questions