Tuesday, February 1, 2022

[SOLVED] Why django don't try search templates in one of app folders?

Issue

I install in Django project virtual enviroment this application https://github.com/badzong/django-xsession and for some reason django can't find template from this application.

In django error page "Template-loader postmortem" in the directories list present another applications, for example django_grappelli-2.8.1-py2.7.egg, django_ckeditor-5.0.3-py2.7.egg and other, but django_xsession-0.1-py2.7.egg are absent. Used this loader:

LOADERS = (
            'django.template.loaders.app_directories.Loader',
    )

django_xsession-0.1-py2.7.egg present in the Python Path

What i do wrong? Why i get error

TemplateDoesNotExist at / django_xsession/loader.html

Upd:

INSTALLED_APPS = [
    'django.contrib.contenttypes',
    'grappelli.dashboard',
    'grappelli',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.sitemaps',
    'django.contrib.staticfiles',
    'sorl.thumbnail',
    'redis',
    'hvad',
    'lazysignup',
    'ckeditor',
.....................................
    'social.apps.django_app.default',
    'django_xsession',
]


TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [
            os.path.join(BASE_DIR, 'templates'),
        ],
        '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',
                'social.apps.django_app.context_processors.backends',
                'social.apps.django_app.context_processors.login_redirect',
            ],
            'debug': DEBUG,
            'loaders': (
                'django.template.loaders.app_directories.Loader',
            ),
        },

    },
]

Templates located in project "templates" dir


Solution

Reason was that application was installed only as .egg without creating folder for application in site-packages.

This happens when i install application with command

python setup.py develop

Where django_xsession was in requires.

But when i installed application with pip and parameter --process-dependency-links (because application located only on github) folder in site-packages was created and template was found.



Answered By - Hayate
Answer Checked By - David Goodson (WPSolving Volunteer)