Offline compression does not load templates with TEMPLATE_LOADERS in settings.py #281

Closed
mattpatey opened this Issue Jun 22, 2012 · 3 comments

Projects

None yet

4 participants

@mattpatey

python manage.py compress -e haml passes HAML templates to a django.template.base.Template:

https://github.com/jezdez/django_compressor/blob/master/compressor/management/commands/compress.py#L143

...
for template_name in templates:
    try:
        template_file = open(template_name)
        try:
            template = Template(template_file.read().decode(
                                    settings.FILE_CHARSET))
        finally:
            template_file.close()
...

The HAML isn't turned into a Django-readable template and thus lines such as %script{src: "/static/javascript/init/head.js"} are never recognized by the compressor when searching for script tags.

This fork uses django.template.loader import.get_template instead, which seems to solve the issue:

https://github.com/ableton-web/django_compressor/blob/develop/compressor/management/commands/compress.py#L215

...
for template_name in templates:
    try:
        template = get_template(template_name)
...
@lagrangee

thanks for it!

@jobelenus

I was similarly surprised that offline generation was looking in STATIC_ROOT for files rather than using TEMPLATE_LOADERS.

@diox
Member
diox commented May 25, 2014

Fixed in #524.

@diox diox closed this May 25, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment