0

I haven't found anything in the Django Docs or any Stack Overflow solutions to this same problem.

Say I have a html file like the following:

{% extends 'base.html' %}
{% block cssfile %}
<!-- css link goes here -->
{% endblock %}
{% block maincontent %}
Hello World
{% endblock %}

which will of course link to base.html. However, I want to put a css file between the 'block cssfile' tags, but given the way that Django is structured for linking static files, it prevents me from doing this.

Something like

{% block cssfile %}
<link rel="stylesheet"type="text/css"href="{% static 'myappname/css/style.css' %}"/>
{% endblock %}

will give me this error

TemplateSyntaxError at /myapp/1/ Invalid block tag on line 3: 'static', expected 'endblock'. Did you forget to register or load this tag?

I've also tried replacing the '{% %}' tags for the href with something like '{{ }}' for example.

Any help would be great, thank you.

jayt
  • 758
  • 1
  • 14
  • 32
  • did you `{% load staticfiles %}`?.. (did you forget to register or load this tag?) – Sayse Sep 14 '16 at 14:55
  • Possible duplicate of [Invalid block tag: 'static'](http://stackoverflow.com/questions/27886477/invalid-block-tag-static) – Sayse Sep 14 '16 at 14:56

1 Answers1

1

You need to put {% load staticfiles %} before use {% static %}

carborgar
  • 171
  • 2
  • 7