{"action":"created","issue":{"url":"https://api.github.com/repos/django-compressor/django-compressor/issues/637","labels_url":"https://api.github.com/repos/django-compressor/django-compressor/issues/637/labels{/name}","comments_url":"https://api.github.com/repos/django-compressor/django-compressor/issues/637/comments","events_url":"https://api.github.com/repos/django-compressor/django-compressor/issues/637/events","html_url":"https://github.com/django-compressor/django-compressor/issues/637","id":96131096,"number":637,"title":"TemplateDoesNotExist is raised when using native Jinja2 support in Django 1.8","user":{"login":"adamjcook","id":654607,"avatar_url":"https://avatars.githubusercontent.com/u/654607?v=3","gravatar_id":"","url":"https://api.github.com/users/adamjcook","html_url":"https://github.com/adamjcook","followers_url":"https://api.github.com/users/adamjcook/followers","following_url":"https://api.github.com/users/adamjcook/following{/other_user}","gists_url":"https://api.github.com/users/adamjcook/gists{/gist_id}","starred_url":"https://api.github.com/users/adamjcook/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adamjcook/subscriptions","organizations_url":"https://api.github.com/users/adamjcook/orgs","repos_url":"https://api.github.com/users/adamjcook/repos","events_url":"https://api.github.com/users/adamjcook/events{/privacy}","received_events_url":"https://api.github.com/users/adamjcook/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/django-compressor/django-compressor/labels/bug","name":"bug","color":"e10c02"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":16,"created_at":"2015-07-20T18:44:00Z","updated_at":"2016-01-19T04:26:35Z","closed_at":null,"body":"Django 1.8 has native Jinja2 template support built-in. Therefore, I am not using Jingo, Coffin or django-jinja. In using the native Jinja2 template support option, however, there seems to be some pretty significant underlying differences in the way that context data is handled and in how Django locates Django app templates when the native Jinja2 is enabled.\r\n\r\nThese are my Django settings for the templates:\r\n```\r\n...\r\nTEMPLATES = [\r\n    {\r\n        'BACKEND': 'django.template.backends.jinja2.Jinja2',\r\n        'DIRS': [\r\n            str(DJANGO_APPS_ROOT_DIR.path('templates')),\r\n        ],\r\n        'APP_DIRS': True,\r\n        'OPTIONS': {\r\n            'environment': 'oiaccount.common.template.jinja2.conf.environment',\r\n            'extensions': [\r\n                'jinja2.ext.i18n',\r\n                'jinja2.ext.autoescape',\r\n                'compressor.contrib.jinja2ext.CompressorExtension'\r\n            ]\r\n        }\r\n    },\r\n]\r\n...\r\n```\r\n\r\nUsing these settings and attempting to use django-compressor will raise the following exception when attempting to render a template. For example, this is the exception raised when the parser encounters a `{% compress css %}` block:\r\n\r\n`django.template.base.TemplateDoesNotExist: compressor/css_file.html`\r\n\r\n**Workaround:**\r\nTo fix this issue, I had to modify the django_compressor package in two (2) ways. If both these changes are not done, a `TemplateDoesNotExist` exception will be raised.\r\n\r\n1. When the `TEMPLATES[APP_DIRS]` Django setting is True, Django looks into each Django app installed for each app's necessary templates. However, when Jinja2 is enabled, it looks for a `jinja2` top-level directory in the app. Therefore, I had to add a copy of the django-compressor template set into `/compressor/jinja2/compressor`. See the picture below.\r\n![screen shot 2015-07-20 at 1 24 13 pm](https://cloud.githubusercontent.com/assets/654607/8783619/b63e2b88-2ee2-11e5-8f59-ead6d07e4b09.png)\r\n2. Unfortunately, probably due to the fact that `context_instance` argument is deprecated starting in Django 1.8 (https://docs.djangoproject.com/en/1.8/topics/http/shortcuts/#render-to-response), enabling Jinja2 seems to totally prevent the `compressor/css_file.html` from being found. To fix this, change:\r\n```\r\nreturn render_to_string(template_name, context_instance=final_context)\r\n```\r\nat https://github.com/django-compressor/django-compressor/blob/develop/compressor/base.py#L345\r\nto\r\n```\r\nreturn render_to_string(template_name, context=final_context.flatten())\r\n```\r\n\r\n**Caveats:**\r\n1. The additional copy needed of the template set seems pretty rough around the edges, but I have yet to figure out a better method.\r\n2. I am not sure if this negatively impacts the situation where Django Templates (DTL) and not Jinja2 templates are used.\r\n\r\nAny comments on my approaches?\r\n\r\nI can make a pull request if the changes that I have made are ultimately acceptable."},"comment":{"url":"https://api.github.com/repos/django-compressor/django-compressor/issues/comments/172733527","html_url":"https://github.com/django-compressor/django-compressor/issues/637#issuecomment-172733527","issue_url":"https://api.github.com/repos/django-compressor/django-compressor/issues/637","id":172733527,"user":{"login":"thenewguy","id":77731,"avatar_url":"https://avatars.githubusercontent.com/u/77731?v=3","gravatar_id":"","url":"https://api.github.com/users/thenewguy","html_url":"https://github.com/thenewguy","followers_url":"https://api.github.com/users/thenewguy/followers","following_url":"https://api.github.com/users/thenewguy/following{/other_user}","gists_url":"https://api.github.com/users/thenewguy/gists{/gist_id}","starred_url":"https://api.github.com/users/thenewguy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thenewguy/subscriptions","organizations_url":"https://api.github.com/users/thenewguy/orgs","repos_url":"https://api.github.com/users/thenewguy/repos","events_url":"https://api.github.com/users/thenewguy/events{/privacy}","received_events_url":"https://api.github.com/users/thenewguy/received_events","type":"User","site_admin":false},"created_at":"2016-01-19T04:26:35Z","updated_at":"2016-01-19T04:26:35Z","body":"@diox pr sent. tests passed"}}