How do I access static files using Jinja in Django
I am using Jinja templating within Django and I am having trouble getting static files to load. I have tried setting up the back end per this documentation (I've included the code below): https://docs.djangoproject.com/en/1.11/topics/templates/#django.template.backends.jinja2.Jinja2
However, I am getting an "Encountered unknown tag 'static'" if I include a {% load static 'path' %} tag. If I include a {% load static %} tag, I get "Encountered unknown tag 'load'." error.
I have setup a "jinja2.py" file in the main folder with the following code:
from django.contrib.staticfiles.storage import staticfiles_storage
from django.urls import reverse
from jinja2 import Environment
def environment(**options):
env = Environment(**options)
env.globals.update({
'static': staticfiles_storage.url,
'url': reverse,
})
return env
settings.py has the following code:
TEMPLATES = [
{
"BACKEND": "django_jinja.backend.Jinja2",
"DIRS": [],
"APP_DIRS": True,
"OPTIONS": {
"environment": 'valuation.jinja2.environment',
}
},
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
Any guidance is very much appreciated.
See above code for what I tried.