# css styles not showing on index.html file, however, they are showing on base.html

**URL:** <https://forum.djangoproject.com/t/css-styles-not-showing-on-index-html-file-however-they-are-showing-on-base-html/36527>\
**Category:** Templates & Frontend\
**Created:** [November 18, 2024, 11:45am UTC](https://forum.djangoproject.com/t/css-styles-not-showing-on-index-html-file-however-they-are-showing-on-base-html/36527 "2024-11-18T11:45:56Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![cozanostra7](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/cozanostra7/32/25235_2.png) [@cozanostra7](https://forum.djangoproject.com/u/cozanostra7)\
**Post date:** [November 18, 2024, 11:45am UTC](https://forum.djangoproject.com/t/css-styles-not-showing-on-index-html-file-however-they-are-showing-on-base-html/36527/1 "2024-11-18T11:45:56Z")

</div>

I can add and edit css styles on base.html file.  
I have another file index.html, which extends from ‘base.html’ using django.

However, i dont know why the css code doesnt work for index.html.

the **base.htm** file

```auto
type or paste code here

{% load static %}
{% load blog_tags %}

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
            <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
            <script defer src="https://use.fontawesome.com/releases/v5.15.4/js/all.js" integrity="sha384-rOA1PnstxnOBLzCLMcre8ybwbTmemjzdNlILg8O7z1lUkLXozs4DHonlDtnE7fpc" crossorigin="anonymous"></script>

    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="{% static 'blog/css/style.css' %}">
    <title>
        {% block title %}

        {% endblock title %}
    </title>
</head>
<body>

<nav class="navbar navbar-expand-lg " style="background-color:#5e8fc1">
  <div class="container-fluid">
    <a class="navbar-brand" href="{% url 'homescreen' %}">Main</a>
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Переключатель навигации">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav me-auto mb-2 mb-lg-0">
        <li class="nav-item">
          <a class="nav-link active" aria-current="page" href="{% url 'homescreen' %}">Главная</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">Ссылка</a>
        </li>
      </ul>
              <ul class="navbar-nav mb-2 mb-lg-0">
                  <li class="nav-item">
                      <form class="d-flex" role="search">
                        <input class="form-control me-2" type="search" placeholder="Поиск" aria-label="Поиск">
                        <button class="btn btn-outline-success" type="submit">Поиск</button>
                        </form>

                  </li>
        <li class="nav-item">
          <a class="nav-link active" aria-current="page" href="#">Sign in</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">Sign up</a>
        </li>
        <li class="nav-item dropdown">
          <a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
            Hello, User
          </a>
          <ul class="dropdown-menu">
            <li><a class="dropdown-item" href="#">My Account</a></li>
            <li><a class="dropdown-item" href="#"> Blog</a></li>
              <li><a class="dropdown-item" href="{% url 'add-article' %}">Write an article</a></li>
            <li><hr class="dropdown-divider"></li>
            <li><a class="dropdown-item" href="#">Sign out</a></li>
          </ul>
        </li>
      </ul>

    </div>
  </div>
</nav>

<br>

<div class="row" >
    <div class="col-lg-4" >
   <a href="{% url 'blogs' %}" class="text-dark m-2"> <i class="fas fa-flask"></i> Blog </a>
    {% get_categories as categories %}
    {% for category in categories %}
    <a href="{% url 'category-view' category.pk %}" class="text-dark m-2"> <i class="fas fa-flask"></i> {{ category.title }} </a>
    {% endfor %}
     </div>
</div>

{% block main %}

{% endblock main %}

<script src="{% static 'blog/js/snow.js' %}"> </script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
</body>
</html>

```

The **index.html** file

```auto
{% extends 'base.html' %}
{% load static %}
{% load blog_tags %}

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<link rel='stylesheet' href="{% static 'blog/css/style.css' %}">
{% block title %}
{{ main_page }}
{% endblock title %}

{% block main %}

<div class="hero-section" style="background-image: url(https://cdn.trend.az/2024/09/09/air-products.png);
height:750px;
background-repeat:no-repeat;
background-size:cover;
"
>
    <div class="row">
        <div class="col-6">
        <h1 style="margin-top:150px" ><strong>Industrial Gas Supplier</strong></h1>
            </div>
    </div>
</div>

<br>
<br>

<div id="carouselExample" class="carousel slide">
  <div class="carousel-inner">
    <div class="carousel-item active" >
      <img src="https://www.newscentralasia.net/wp-content/uploads/2023/09/air-products-co.jpg" class="d-block w-100" alt="...">
    </div>
    <div class="carousel-item">
      <img src="https://www.gasworld.com/cdn-cgi/image/width=1200,height=900,fit=contain,quality=75,metadata=none,format=auto,gravity=auto/https://www.gasworld.com/wp-content/files/gwml/actros2545airproducts21_185696.jpg" class="d-block w-100" alt="...">
    </div>
    <div class="carousel-item">
      <img src="..." class="d-block w-100" alt="...">
    </div>
  </div>
  <button class="carousel-control-prev" type="button" data-bs-target="#carouselExample" data-bs-slide="prev">
    <span class="carousel-control-prev-icon" aria-hidden="true"></span>
    <span class="visually-hidden">Previous</span>
  </button>
  <button class="carousel-control-next" type="button" data-bs-target="#carouselExample" data-bs-slide="next">
    <span class="carousel-control-next-icon" aria-hidden="true"></span>
    <span class="visually-hidden">Next</span>
  </button>
</div>

<!--<div class="container">-->
<!-- {% for article in articles %}-->

<!-- <div class="card mt-4 mb-4">-->
<!-- <div class="d-flex justify-content-center">-->
<!-- <div class="col-3">-->
<!-- <a href="{% url 'article-view' article.pk %}">-->
<!-- <img height="200px" src="https://media.istockphoto.com/id/1354826805/vector/data-science.jpg?s=612x612&w=0&k=20&c=FKYxpsaWX7H5_DEX4t0dV2o837_aqgoavlIRdIz1jwE=" alt="">-->
<!-- </a>-->
<!-- </div>-->
<!-- <div class="col-9 p-4">-->
<!-- <a href="{% url 'article-view' article.pk %}" class="text-dark"><h3> {{ article.title }} </h3></a>-->
<!-- <p>{{ article.description }}</p>-->
<!-- <span class="small">{{ article.created_at }}</span>-->
<!-- <p> {{ article.category }} </p>-->
<!-- </div>-->
<!-- </div>-->
<!-- </div>-->

<!-- {% endfor %}-->

<!--</div>-->

{% endblock main %}

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>

```

the **style.css** file

```auto
.ball {
  position: absolute;
  border-radius: 100%;
  opacity: 0.7;
}

#carouselExample {
    height: 300px;
    width: 300px;
}

```

The applied style and js code on base.html are working great. But they dont work for index.html

I uploaded all the routes, wrote the code in settings.py correctly. But still now working for index.html

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [November 18, 2024, 12:35pm UTC](https://forum.djangoproject.com/t/css-styles-not-showing-on-index-html-file-however-they-are-showing-on-base-html/36527/2 "2024-11-18T12:35:41Z")

</div>

Welcome @cozanostra7 !

Your two `<link ` elements at the beginning and the `<script` element at the end aren’t inside blocks.

When you are extending a base template, everything you render within the child template must be in a block - otherwise, the template engine doesn’t have a place to put it in the page being rendered.

See the docs on [Template inheritance](https://docs.djangoproject.com/en/5.1/ref/templates/language/#template-inheritance) for more details about this.

---

<div class="post-metadata">

**Author:** ![philgyford](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/philgyford/32/14295_2.png) [@philgyford](https://forum.djangoproject.com/u/philgyford)\
**Post date:** [November 18, 2024, 1:45pm UTC](https://forum.djangoproject.com/t/css-styles-not-showing-on-index-html-file-however-they-are-showing-on-base-html/36527/3 "2024-11-18T13:45:07Z")

</div>

But the CSS and JS files in index.html are also in base.html, outside blocks.

So you should be able to remove them from index.html. But, also, it should be working, and I’m not sure why it isn’t.

Can you see a request for the style.css file in the logs when you load the page in the browser?

---

<div class="post-metadata">

**Author:** ![stuartmaxwell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/stuartmaxwell/32/1135_2.png) [@stuartmaxwell](https://forum.djangoproject.com/u/stuartmaxwell)\
**Post date:** [November 19, 2024, 3:54am UTC](https://forum.djangoproject.com/t/css-styles-not-showing-on-index-html-file-however-they-are-showing-on-base-html/36527/4 "2024-11-19T03:54:07Z")

</div>

This _should_ be working, even though you’ve made some mistakes. For starters, in your index.html file, remove the link tags and the script tags - these are not doing anything because they are not inside blocks, and you’ve already included them in your base.html file anyway. Then open your developer tools, go to the network tab and reload the view that uses the index.html file. You should see requests for the CSS and the JavaScript files.

If not, then you need to do more troubleshooting. I assume you’re running locally, so make sure you’ve got DEBUG set to True, and I also recommend installing and configuring django-debug-toolbar as that will give you lots of info about what’s going on with your templates.

Is it possible that you’re inheriting the wrong base.html? Do you have multiple templates called base.html?

---

<div class="post-metadata">

**Author:** ![cozanostra7](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/cozanostra7/32/25235_2.png) [@cozanostra7](https://forum.djangoproject.com/u/cozanostra7)\
**Post date:** [November 20, 2024, 10:47am UTC](https://forum.djangoproject.com/t/css-styles-not-showing-on-index-html-file-however-they-are-showing-on-base-html/36527/5 "2024-11-20T10:47:11Z")

</div>

hello.  
Its says Not Found: /…

But any change made in base.html for CSS is working well

---

<div class="post-metadata">

**Author:** ![cozanostra7](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/cozanostra7/32/25235_2.png) [@cozanostra7](https://forum.djangoproject.com/u/cozanostra7)\
**Post date:** [November 20, 2024, 10:49am UTC](https://forum.djangoproject.com/t/css-styles-not-showing-on-index-html-file-however-they-are-showing-on-base-html/36527/6 "2024-11-20T10:49:03Z")

</div>

well, changes in base.html are working well, I can modify styles by changing the CSS file

---

<div class="post-metadata">

**Author:** ![philgyford](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/philgyford/32/14295_2.png) [@philgyford](https://forum.djangoproject.com/u/philgyford)\
**Post date:** [November 20, 2024, 5:41pm UTC](https://forum.djangoproject.com/t/css-styles-not-showing-on-index-html-file-however-they-are-showing-on-base-html/36527/7 "2024-11-20T17:41:54Z")

</div>

> Its says Not Found: /…

What does? If there is more of the error message, please show it in full and describe where it comes from (your browser (if so, for what URL)? your logs? your browser’s Network tab?).

When you say the CSS “doesn’t work for index.html” can you describe what you mean in a lot more detail? What are you changing, in what file?

---

<div class="post-metadata">

**Author:** ![cozanostra7](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/cozanostra7/32/25235_2.png) [@cozanostra7](https://forum.djangoproject.com/u/cozanostra7)\
**Post date:** [November 27, 2024, 7:08am UTC](https://forum.djangoproject.com/t/css-styles-not-showing-on-index-html-file-however-they-are-showing-on-base-html/36527/8 "2024-11-27T07:08:10Z")

</div>

Hi dear!

May i share the developer tool with ypu?  
Here is the screenshot:

 ![screenshot.197](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/3X/b/8/b8f381e74d6a4c08ec2e3f4a66035884a3514760.jpeg)a

Please kindly check it

---

<div class="post-metadata">

**Author:** ![stuartmaxwell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/stuartmaxwell/32/1135_2.png) [@stuartmaxwell](https://forum.djangoproject.com/u/stuartmaxwell)\
**Post date:** [November 27, 2024, 7:11am UTC](https://forum.djangoproject.com/t/css-styles-not-showing-on-index-html-file-however-they-are-showing-on-base-html/36527/9 "2024-11-27T07:11:27Z")

</div>

Do you really have a directory in your project called: “static/blog/css”?

---

<div class="post-metadata">

**Author:** ![cozanostra7](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/cozanostra7/32/25235_2.png) [@cozanostra7](https://forum.djangoproject.com/u/cozanostra7)\
**Post date:** [November 27, 2024, 7:17am UTC](https://forum.djangoproject.com/t/css-styles-not-showing-on-index-html-file-however-they-are-showing-on-base-html/36527/10 "2024-11-27T07:17:06Z")

</div>

here it is:

 ![screenshot.198](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/3X/2/2/22d2e14deca995ccb291d98e26bc761c8dd2208b.jpeg)f

this folder is in “portfolio” project folder, not in the app folder

---

<div class="post-metadata">

**Author:** ![stuartmaxwell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/stuartmaxwell/32/1135_2.png) [@stuartmaxwell](https://forum.djangoproject.com/u/stuartmaxwell)\
**Post date:** [November 27, 2024, 7:24am UTC](https://forum.djangoproject.com/t/css-styles-not-showing-on-index-html-file-however-they-are-showing-on-base-html/36527/11 "2024-11-27T07:24:25Z")

</div>

And do you have your static files properly configured in settings.py. Should look something like this:

```python
# The path that the static files will be served from
STATIC_URL = "/static/"
# The directory that collectstatic will collect static files to
STATIC_ROOT = BASE_DIR / "staticfiles"
# The directory that static files will be collected from
STATICFILES_DIRS = [
    BASE_DIR / "static",
]

```

---

<div class="post-metadata">

**Author:** ![cozanostra7](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/cozanostra7/32/25235_2.png) [@cozanostra7](https://forum.djangoproject.com/u/cozanostra7)\
**Post date:** [November 27, 2024, 7:28am UTC](https://forum.djangoproject.com/t/css-styles-not-showing-on-index-html-file-however-they-are-showing-on-base-html/36527/12 "2024-11-27T07:28:28Z")

</div>

urls

```auto
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

```

settigns

```auto
STATIC_URL = 'static/'
STATIC_ROOT = BASE_DIR / 'static'

MEDIA_URL = '/media/'
MEDIA_ROOT = BASE_DIR / 'media'

```

and i did collectstatic … still no help

---

<div class="post-metadata">

**Author:** ![cozanostra7](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/cozanostra7/32/25235_2.png) [@cozanostra7](https://forum.djangoproject.com/u/cozanostra7)\
**Post date:** [November 27, 2024, 7:45am UTC](https://forum.djangoproject.com/t/css-styles-not-showing-on-index-html-file-however-they-are-showing-on-base-html/36527/13 "2024-11-27T07:45:28Z")

</div>

moreover, newly written codes are not shown on developer tools:

 ![screenshot.199](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/3X/8/4/845361f3a4efa8c21ec7836d8f42d192fc2b39c1.jpeg)

---

<div class="post-metadata">

**Author:** ![stuartmaxwell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/stuartmaxwell/32/1135_2.png) [@stuartmaxwell](https://forum.djangoproject.com/u/stuartmaxwell)\
**Post date:** [November 27, 2024, 7:56am UTC](https://forum.djangoproject.com/t/css-styles-not-showing-on-index-html-file-however-they-are-showing-on-base-html/36527/14 "2024-11-27T07:56:55Z")

</div>

OK, for starters - you shouldn’t have STATIC\_ROOT set to `BASE_DIR / 'static'`. This will confuse Django when you run the `collectstatic` command. Running `collectstatic` will look for directories called `static` and copy them into the `STATIC_ROOT` directory. So in your case, you’re telling Django to copy files to the same location that your files are already in. You probably have seen warnings when doing this. The fix is set `STATIC_ROOT` to a different value, e.g. `STATIC_ROOT = BASE_DIR / "staticfiles"` (really that can be anything, but `staticfiles` is a common value used in lots of tutorials.)

I recommend fixing that first.

Also, I mis-read your earlier screenshot. Your static files are being served correctly as can be seen in your last screenshot. So what you are saying is that you are modifying the `style.css` file but the changes aren’t being reflected when you reload the sever? That might be caused by the first issue, or it might just be a browser caching issue.

The last thing I’ll mention is that the way you have configured your urlpatterns is OK for development, but not for production. The easiest thing to do will be to install and configure Whitenoise if you want Django to serve both your Python code and your static files. [Using WhiteNoise with Django - WhiteNoise 6.8.2 documentation](https://whitenoise.readthedocs.io/en/stable/django.html) (you need to do step 1 and 2 at a minimum to get it working)

---

<div class="post-metadata">

**Author:** ![cozanostra7](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/cozanostra7/32/25235_2.png) [@cozanostra7](https://forum.djangoproject.com/u/cozanostra7)\
**Post date:** [November 27, 2024, 10:03am UTC](https://forum.djangoproject.com/t/css-styles-not-showing-on-index-html-file-however-they-are-showing-on-base-html/36527/15 "2024-11-27T10:03:49Z")

</div>

I did so… still not working.

I even tried to apply jQuery - not applying the CSS styles

---

<div class="post-metadata">

**Author:** ![stuartmaxwell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/stuartmaxwell/32/1135_2.png) [@stuartmaxwell](https://forum.djangoproject.com/u/stuartmaxwell)\
**Post date:** [November 27, 2024, 10:15am UTC](https://forum.djangoproject.com/t/css-styles-not-showing-on-index-html-file-however-they-are-showing-on-base-html/36527/16 "2024-11-27T10:15:34Z")

</div>

It’s difficult to understand exactly what the issue is or what you have fixed. I’m also not sure why jQuery is now in the mix? Are your styles not being applied or are they not even making it into the styles.css file?

---

<div class="post-metadata">

**Author:** ![cozanostra7](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/cozanostra7/32/25235_2.png) [@cozanostra7](https://forum.djangoproject.com/u/cozanostra7)\
**Post date:** [November 27, 2024, 10:18am UTC](https://forum.djangoproject.com/t/css-styles-not-showing-on-index-html-file-however-they-are-showing-on-base-html/36527/17 "2024-11-27T10:18:41Z")

</div>

well, whatever i wrote on style.css file, it is not reflected on pages

---

<div class="post-metadata">

**Author:** ![cozanostra7](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/cozanostra7/32/25235_2.png) [@cozanostra7](https://forum.djangoproject.com/u/cozanostra7)\
**Post date:** [November 27, 2024, 11:26am UTC](https://forum.djangoproject.com/t/css-styles-not-showing-on-index-html-file-however-they-are-showing-on-base-html/36527/18 "2024-11-27T11:26:51Z")

</div>

![screenshot.200](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/3X/a/e/aefeb6583e19095f05bc0450bc248419855963fa.jpeg)

well now it says another issue. Here it is …  
I think the problem was before , just it didn’t show up

---

<div class="post-metadata">

**Author:** ![stuartmaxwell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/stuartmaxwell/32/1135_2.png) [@stuartmaxwell](https://forum.djangoproject.com/u/stuartmaxwell)\
**Post date:** [November 27, 2024, 7:15pm UTC](https://forum.djangoproject.com/t/css-styles-not-showing-on-index-html-file-however-they-are-showing-on-base-html/36527/19 "2024-11-27T19:15:38Z")

</div>

This is a different issue than before and you need to read this page to solve it: [How to manage static files (e.g. images, JavaScript, CSS) | Django documentation | Django](https://docs.djangoproject.com/en/5.1/howto/static-files/)
