15

Here is the error I got:

ImproperlyConfigured: Error importing template source loader django.template.loaders.filesystem.load_template_source: "'module' object has no attribute 'load_template_source'"

Here is my loader template code:

if DEBUG:
    TEMPLATE_LOADERS = [
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',      
    ]
else:
    TEMPLATE_LOADERS = [
        ('django.template.loaders.cached.Loader',(
            'django.template.loaders.filesystem.load_template_source',
            'django.template.loaders.app_directories.load_template_source',
            'forum.modules.template_loader.module_templates_loader',
            'forum.skins.load_template_source',
            )),
    ]

All of this code was there when I downloaded the project from the internet. I'm trying to setup OSQA using these instructions. I'm running MS SQL Server and have Python 2.6 installed. Any help on how to fix this error (found when I try to run manage.py runserver and hit the http link where my stuff is setup. the error pops up in the command line). I'm new to Django and Python so I don't really know to how to diagnose what is happening.

Santosh Kumar
  • 26,475
  • 20
  • 67
  • 118
dudebroman
  • 256
  • 2
  • 4
  • 12
  • Compare the two TEMPLATE_LOADERS in detail. The actual problem was trying to use the old *.filesystem.load_template_source and *.app_directories.load_template_source... should be *.filesystem.Loader. However great answer @girasquid – Daniel Backman Aug 22 '13 at 19:32

2 Answers2

26

If you look at the documentation on template loader types (scroll down to the cached template loader section), it looks like when you configure the cached loader you still need to pass it Loader classes - so you'd want to change your config to look like this:

if DEBUG:
    TEMPLATE_LOADERS = [
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',      
    ]
else:
    TEMPLATE_LOADERS = [
        ('django.template.loaders.cached.Loader',(
            'django.template.loaders.filesystem.Loader',
            'django.template.loaders.app_directories.Loader',
            'forum.modules.template_loader.module_templates_loader',
            'forum.skins.load_template_source',
            )),
    ]

I'm not sure what the loaders are for the forum app, but you probably also want Loader classes there as well (you'll need to read the documentation on that app to figure that out - not all third party template loaders work with the cached loader).

girasquid
  • 15,121
  • 2
  • 48
  • 58
  • I think that fixed it because now I'm getting a different error :) which I'm pretty sure is different than this one... – dudebroman Aug 10 '12 at 15:30
  • Note - the function based template loaders were removed in Django 1.4: https://docs.djangoproject.com/en/1.10/internals/deprecation/#deprecation-removed-in-1-4. – Duncan Parkes Mar 20 '17 at 15:02
4
  1. Open the ‘settings.py‘ file in the folder which contains the extracted contents of the Twissandra project.
  2. Search, ‘TEMPLATE_LOADERS=(‘ and within it, search, ‘django.template.loaders.filesystem.load_template_source‘. Comment this line and add, ‘django.template.loaders.filesystem.Loader‘.
  3. Similarly, within ‘TEMPLATE_LOADERS=(‘, search, ‘django.template.loaders.app_directories.load_template_source‘, and replace it with, ‘django.template.loaders.app_directories.Loader‘.

P.S. I solved my problem and thanks How to fix the Django error displayed when loading Twissandra for the first time?

jammyWolf
  • 2,743
  • 1
  • 13
  • 7