Closed abhimanyub closed 7 years ago
Do you have django_jinja on INSTALLED_APPS ?
In any case, seems like a configuration issue (something that depends on the environment on you are runing your, I don't know).
Yes I've added that to my installed apps right before the template configuration. Anything else I need to update.
I'm using Django 1.9.5 django-jinja 2.2.1 Jinja2 2.7
I am able to use Jinja and load the template explicitly using jinja2 backend. But, I want to use django-jinja
I don't know how I can help you. Something is wrong in your config or environment or both. On my tests on my own projects and the test suite of the django-jinja, everything should work as expected.
@abhimanyub I do not know if this would help you now, since this has been quite a while. However, I had a similar problem (albeit with Django 2.1) and the following configuration helped me figure out how to use django-jinja.
Essentially, the problem is that django-jinja does not automatically identify the relevant template directly used by the default template engine. You need to explicitly declare a value for "DIRS". Secondly, "match_extension" needs to contain all of the template extensions that would be used, ideally, HTML (you do not need the ".jinja" extension but you can leave it in if you like).
To give you an example of how I got the system to work, here is my configuration:
{
"BACKEND": "django_jinja.backend.Jinja2",
'DIRS': [os.path.join(BASE_DIR, 'templates')], # This needs to be explicitly declared
"APP_DIRS": True,
"OPTIONS": {
"match_extension": (
".html", # Remember to include the default extension of your template files
".jinja",
), # This is a tuple, do not use a list
"extensions": [
"jinja2.ext.do",
"jinja2.ext.loopcontrols",
"jinja2.ext.with_",
"jinja2.ext.i18n",
"jinja2.ext.autoescape",
"django_jinja.builtins.extensions.CsrfExtension",
"django_jinja.builtins.extensions.CacheExtension",
"django_jinja.builtins.extensions.TimezoneExtension",
"django_jinja.builtins.extensions.UrlsExtension",
"django_jinja.builtins.extensions.StaticFilesExtension",
"django_jinja.builtins.extensions.DjangoFiltersExtension",
],
"bytecode_cache": {
"name": "default",
"backend": "django_jinja.cache.BytecodeCache",
"enabled": False,
},
}
},
I hope this helps someone. Cheers!
Thanks for the help. We solved this problem by a similar approach. Thanks again :)
@abhimanyub what was your approach? I'm having the same issue and @srivatsshankar 's suggestion does not help. Thank you
After setting up as mentioned in the quick start quide. Django is still not using Jinja2 as the default template engine.
My setting :
Kindly help. Thanks