I have a layout.html file as follows:
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<link href="{% static 'app/styles.css' %}" rel="stylesheet">
</head>
<body>
{% block body %}
{% endblock %}
</body>
</html>
and a extended.html as follows:
{% extends "layout.html" %}
{% block body %}
<div class="maincontainer">
<h1>Extended</h1>
<img src="{% static 'app/images/image.svg' %}" alt="image">
</div>
{% endblock %}
When I load the exnteded.html I get the follwoing error:
django.template.exceptions.TemplateSyntaxError: Invalid block tag on line 13: 'static', expected 'empty' or 'endfor'. Did you forget to register or load this tag?
I have tested a few scenarios out:
- If I remove the
<img src="{% static 'app/images/image.svg' %}" alt="image">from the extended.html the CSS style sheet loads perfectly. - If I add
{% load static %}to the extended.html the image and CSS style sheet both load.
I have had a look at the Django docs and have ensured that the settings.py file does have django.contrib.staticfiles in INSTALLED_APPS and STATIC_URL = "static/".
Am I missing something here?
You don't define
app nameinload static.You have just try to remove app name in your load static, Like,
Your
code:Try
My Answer:And also remove
appname in load images,Your
code:Try
My Answer: