blueFast
blueFast

Reputation: 44491

Django does not find template, but it exists, and it even acknowledges it

TemplateDoesNotExist raised, but the postmortem says it finds one template:

Template-loader postmortem

Django tried loading these templates, in this order:
Using loader django.template.loaders.filesystem.Loader:
Using loader django.template.loaders.app_directories.Loader:
/blah-blah/venv2.7/local/lib/python2.7/site-packages/django/contrib/admin/templates/shopify_app/login.html (File does not exist)
/blah-blah/venv2.7/local/lib/python2.7/site-packages/django/contrib/auth/templates/shopify_app/login.html (File does not exist)
/blah-blah/venv2.7/local/lib/python2.7/site-packages/tinymce/templates/shopify_app/login.html (File does not exist)
/blah-blah/venv2.7/local/lib/python2.7/site-packages/django_tables2/templates/shopify_app/login.html (File does not exist)
/blah-blah/venv2.7/local/lib/python2.7/site-packages/crispy_forms/templates/shopify_app/login.html (File does not exist)
/blah-blah/ppmsys/shopify_app/templates/shopify_app/login.html (File exists)
/blah-blah/ppmsys/campaigns/templates/shopify_app/login.html (File does not exist)
/blah-blah/venv2.7/local/lib/python2.7/site-packages/django_extensions/templates/shopify_app/login.html (File does not exist)

The file is readable.

» ls -l ppmsys/shopify_app/templates/shopify_app/login.html 
-rw-rw-r-- 1 user1 user1 749 Nov  6 11:55 ppmsys/shopify_app/templates/shopify_app/login.html

Why is TemplateDoesNotExist raised? Any ideas on what to try next?

This is the relevant part of my settings:

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.webdesign', # for {% lorem %}

    # Added by me
    'storages',
    'phonenumber_field', # for PhoneNumberField
    'tinymce', # from django-tinymce, for HTMLField
    'django_tables2', # from django-tables2
    'crispy_forms', # from django-crispy-forms
    'shopify_app', # taken from https://github.com/Shopify/shopify_django_app

    # My applications
    'mockups',
    'campaigns',
]

...

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [
        ],
        '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',
                'django.core.context_processors.request',
            ],
            'loaders': [
                'django.template.loaders.filesystem.Loader',
                'django.template.loaders.app_directories.Loader',
            ]
        },
    },
]

Upvotes: 0

Views: 497

Answers (2)

blueFast
blueFast

Reputation: 44491

Ok, I found it. It is stupid, but I'll leave it here for reference to others.

The template comes from an application that I am reusing. I have seen that it does:

{% extends "base.html" %}
{% block content %}
...
{% endblock %}

And base.html does not exist anywhere.

Fine. I have no base template, and I should be punished for it. But not with a TemplateDoesNotExist with a misleading debug message.

It specifically says that shopify_app/login.html does not exist, but what doesn't exist is base.html. That is misleading imho. I spent one hour tweaking my settings to let django find the template that I knew was there!

Upvotes: 3

Marcos R. Guevara
Marcos R. Guevara

Reputation: 6408

from os.path import join, normpath

then

'DIRS': [
            normpath(join(BASE_DIR, 'templates')),
        ],
        'APP_DIRS': True,

Upvotes: 0

Related Questions