Reputation: 117
I have a template.html file full of some boiler plate html text.
Then in index.html I have:
{% load static %}
{% extends static 'template.html' %}
In settings.py I have (relevent things):
INSTALLED_APPS = [
'notes.apps.NotesConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
STATIC_URL = '/static/'
However, when I try to render index.html I get a
TemplateSyntaxError at 'extends' takes one argument
.
When template.html was placed in the same directory as index.html and I used
{% extends 'template.html' %}
everything worked fine.
Upvotes: 0
Views: 228
Reputation: 2607
If you use {% extends %} in a template, it must be the first template tag in that template. Template inheritance won’t work, otherwise.
We'll that is according to the documentation, so I am not sure you can load static.
The question is why do you wish to extend static? Move it to templates and then extend the usual way.
Upvotes: 1
Reputation: 666
It seems like you need to add a reference to your static folder so that Django knows where to look for static files.
For that, you need to add the following lines of code in your settings.py
file.
Assuming that you have a folder for static files in the base directory, the same place where the manage.py
file lives. You just need to add the following lines to your settings.py
.
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'staticfiles'),
]
# Assuming the name of your static files folder is "staticfiles"
Upvotes: 0