caktus / django-styleguide

Styleguide helper for projects that work with design teams
BSD 3-Clause "New" or "Revised" License
12 stars 3 forks source link

get_styleguide_dirs throws an error with cached.Loader in Django 1.8 #52

Open nmashton opened 6 years ago

nmashton commented 6 years ago

When using the django.template.loaders.cached.Loader template loader (which is enabled by default whenever DEBUG is off and which is explicitly set to be on in the base settings of my project), you get this error trying to view the styleguide root page:

AttributeError at /styleguide/
'Loader' object has no attribute 'get_template_sources'

The error is happening here:

for template_dir in loader.get_template_sources('styleguide'):

The problem is that the cached loader doesn't have a get_template_sources method. The loaders that it wraps do, and those can be accessed via its loaders attribute, but it itself does not. (This is true at least in Django 1.8, which is what this project currently uses.)

So I guess we need to find some more robust way to find the styleguide templates. One approach would be to just check whether there's a loaders value to iterate over and use those. Another might be to do something inspired by what get_app_template_dirs does.