Trying to load a css stylesheet from a child template in django

Viewed 512

I have a parent template with this code

<head>
    <meta charset="UTF-8">
    <title>{% block title %}{% endblock %}</title>
    {% load static %}
    <link rel="stylesheet" href="{% static 'base.css' %}"/>
    {% block additionalStyles %}{% endblock %}
</head>

and I have a child template with this code

{% extends 'base.html' %}
{% load static %}
{% block additionalStyles %}<link rel="sytlesheet" href="{% static 'rants.css' %}"/>{% endblock %}

this doesn't seem to work and I don't get an error either. The base.css loads fine and when I inspect element on the webpage I can see <link rel="sytlesheet" href="static/rants.css"/> in the HTML code but it doesn't have any affect on any of the elements that it should. Is there a better way of doing this? and why is it not working?

Edit: It magically started working?? idk why or how, here is the new code if anyone has the same problem, in child:

{% extends "base.html" %}
{% load static %}
{% block title %}Rants{% endblock %} 
{% block additionalStyles %}
<link rel="stylesheet" href="{% static 'rants.css' %}"/>
{% endblock %}

in parent:

    {% load static %}
    <title>{% block title %}{% endblock %}  </title>
    <link rel="stylesheet" href="{% static 'base.css' %}"/>
    {% block additionalStyles %} {% endblock %}
2 Answers
  1. Kindly check the path to the folder that has the CSS file.

  2. When everything seems to work correctly, remember to clear your browser cache or load the site/app in incognito mode(for Google Chrome users). In the child

     {% extends "base.html" %}
     {% load static %}
     {% block title %}Rants{% endblock %} 
     {% block additionalStyles %}
         <link rel="stylesheet" href="{% static 'path_to_folder/rants.css' %}"/>
     {% endblock %}
    

In the parent

  {% load static %}
    <title>Parent site{% block title %}{% endblock %}  </title>
    <link rel="stylesheet" href="{% static 'path_to_folder/base.css' %}"/>
    {% block additionalStyles %} {% endblock %}

Need to give the <link> it's own line

{% extends "base.html" %}
{% load static %}
{% block title %}Rants{% endblock %} 
{% block additionalStyles %}
<link rel="stylesheet" href="{% static 'rants.css' %}"/>
{% endblock %}

Now works

Related