UnboltingZero0
UnboltingZero0

Reputation: 33

html doc not using external css style sheet

I am starting to learn CSS and after trying to implement an external stylesheet, i found I was unable to change the color of my html document. I am using Visual Studio Code and my html templates are using Djangos inheritance.

I have tried double checking that everything is saved, I have checked spelling for the href, and i even restarted VSC. So far nothing.

Here is the base html sheet

<!DOCTYPE html>
<html lang="en">
    <head>
      <meta charset="utf-8">
        {% block style %}
        {% endblock %}
     <title>
         {% block title %}
         {% endblock %}
     </title>
</head>
<body>
  {% block content %}
  {% endblock %}
</body>

</html>

Here is an html sheet that should use the styling:

{% extends 'student_view_base.html' %}


{% block title %}
    Socrates Home Page
{% endblock %}

{% block style %}
<link rel="stylesheet" type="text/css" 
 href="css/sidebar.css">    
{% endblock %}


{% block content %}
    <h1>Socrates Home Page</h1>
    <div>
        <a href="{% url 'login' %}">Login</a>
    </div>
    <a href="{% url 'admin:index' %}">Admin Login</a>
{% endblock %}

Here is the css sheet:

h1{
    color: blue;
}

As you can tell, I am pretty new to Web Dev in general and this was mostly to experiment and make sure I could implement it properly.

As far as I can tell the h1 tags text should be turning blue. Currently it remains black.

EDIT: I can confirm that the href is linked to the proper document, ctrl clicking takes me to the right document.

Upvotes: 1

Views: 141

Answers (1)

Anjaan
Anjaan

Reputation: 656

You are better off placing your html code on templates and your css on static when you use django. Create a templates and static folders on your project as here. enter image description here

Then edit settings.py'DIRS': [os.path.join(BASE_DIR, 'templates')], inside TEMPLATES. Also add the following code to your settings.py :

STATIC_URL = '/static/'

STATIC_DIRS = [
    os.path.join(BASE_DIR, 'static'),
]

STATIC_ROOT = os.path.join(BASE_DIR, 'static')


MEDIA_URL = '/media/'

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

You should be good to go.

Upvotes: 2

Related Questions