Django CSS not loading properly on webpage after initial load

I am having trouble understanding why the main.css file is not loading properly in my Django project. I am using the skeleton boilerplate and trying to change the background color, but the changes are not reflecting on the webpage. It's strange because when I run python3 manage.py runserver, it displays the initial values from my original main.css file that were set at the beginning of the project. However, when I make changes to the main.css file, the webpage still shows the original values.

  • First, I created a static folder outside my app directory in the project.
  • Then, I added a CSS folder within the static folder.
  • After that, I included the skeleton.css, normalize.css, and main.css files.

In my index.html file, I linked the static folder along with the skeleton CSS files and main CSS files in the head tags.

{% load static %}

<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="{% static 'css/normalize.css' %}"/>
<link rel="stylesheet" href="{% static 'css/skeleton.css' %}"/>
<link rel="stylesheet" href="{% static 'css/main.css' %}"/>

<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4d2e252c3f3963273e0d7f6375637d">[email protected]</a>"></script>

<meta charset="UTF-8">
<title>index</title>
</head>

Everything seems fine until this point. The confusion arises when I try to modify the styles in the main.css file to change the background color and layout.

body {
background: #505f73;
}

.container {
background: #FF0000;
margin-bottom: 50px;
margin-top: 50px;
padding: 25px;
text-align: center;
}

https://i.sstatic.net/2Pmpf.png

The initial output was exactly what I wanted while coding the site. But now, when attempting to change the background-color property in the main.css file, no visible change occurs on the webpage. Even after modifying the hex code for the background color, the page still displays the original values. Deleting everything in the main.css file and reloading the webpage still results in showing the original output as seen above.

Any insights into what might be causing this issue?

Note: I have already added the following lines to my settings.py file:

STATIC_URL = '/static/'
STATICFILES_DIRS = (os.path.join('static'),)

Please refer to the attached directory structure image below:

https://i.sstatic.net/kk1QK.png

Answer №1

When working on a development server, it is important to ensure that the DEBUG variable in your settings is set to True.

#settings.py
DEBUG = True

Answer №2

Ensure that the static file (main.css) in your project is organized according to the following file structure:

yourproject/app/static/app/main.css
.

To import your app in HTML, use the following code snippet:

<link rel="stylesheet" href="{% static 'app/main.css' %}"/>

Answer №3

After some investigation, I've identified the root cause of the issue. It appears that the problem lies not with how Django is loading the files, but rather with the browser I was initially using (Safari). Safari was storing the cache of the Django website, which was preventing the changes from being reflected in main.css. Switching over to Chrome has resolved the issue, as it now accurately shows all the modifications I make in the CSS file. Although clearing the cache in Safari temporarily fixed the problem, I would prefer not to have to do this every time I want to test the site. Therefore, for the time being, I will continue using Chrome.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The concepts of width and min-width in CSS allow for controlling

I have a table with the following styles applied: width: auto; min-width: 98.5%; When viewing in Chrome, the table inside a div appears to only be about 50% of the width of the containing div. However, in IE9, the table occupies the full width. Checking ...

limited growth of float variable

I am utilizing CSS code to create column a and column b, using float in the code to dynamically expand column a as content is added to column b. However, this expansion is not occurring as expected. To see my code, please visit http://jsfiddle.net/hadinetc ...

What is the best way to define a Django application scope variable?

Is there a way to establish an application-wide variable in Django that is loaded at app start, remains in memory, and can be accessed by all parts of the application? I'm looking for a solution that allows me to reuse the variable without needing to ...

Are Firefox and Internet Explorer experiencing issues with CSS rendering accurately?

Experiencing some problems with IE and Firefox CSS To see the issue, visit Check it out in Chrome - it's displaying correctly there But when you view it in IE or Firefox, it's acting strange. Am I making a mistake somewhere? Any help would b ...

utilizing different background colors for rows in a Laravel table using CSS

Is there a way to implement alternate row coloring in a Laravel table using CSS? I want to have different colors for every other row. I have applied the "gridview" CSS class to the table. Specifically, I want to use the .gridview tr.even td selector for th ...

Is AJAX malfunctioning while the success function is functioning properly?

the function for success is operational, however the data isn't being saved in the database $(document).ready(function() { $("#ChatText").keyup(function(e){ if(e.keyCode == 13) { var ChatText = $("#ChatText").val(); ...

Chrome's display of HTML5 form validation bubble is not aligned correctly

Can anyone shed some light on why the Form Validation Bubble is showing up with a big offset in Google Chrome when trying to validate a form inside a jquery UI dialog? It seems to work fine when the javascript call creating the dialog is removed. Just want ...

Unable to meet the prerequisites for Docker installation

I'm encountering issues with starting docker on my Windows computer. Initially, it goes through the typical process of downloading files but then I start getting error messages like below. WARNING: Retrying (Retry(total=4, connect=None, read=None, ...

The image has max-height within a max-height container inside a fixed-height container

Here's the scenario: Can an image's max-height property be made to respect the fixed height of an ancestor element that is not its direct parent? I am aware that max-height requires a fixed height for calculation, so this query is distinct from ...

What is the best way to assign a URL to an image source using a JavaScript variable?

I am working on a script that displays different image URLs based on the time of day using an if-else statement. I want to dynamically load these images in an img src tag so that a different picture is loaded for each time of day. I have defined variables ...

How can I enhance Parallax scrolling performance on Chrome?

I recently completed a tutorial from the following link: After customizing it by changing the image to something different than clouds, I noticed that my version of the website was experiencing lag issues in Chrome but worked fine in Firefox. However, whe ...

Navigating to a webpage using a dropdown menu selection and a button press

I'm new to Angular and wondering if it's possible to select an option from a dropdown menu and then be redirected to a specific page based on that selection <mat-label >Login As</mat-label> <mat-select> ...

Personalize the md-tab component in Angular 2

I'm encountering an issue with styling the md-tab component in Angular 2. While I understand that Angular 2 Materials is currently under development, I am wondering if there is a way to customize it, such as removing the bottom-radius. Below is an exa ...

Creating a dynamic button with Angular that appears when focused

I want to have a button appear when the user focuses on an input with the ng-model=query. I know there is an ng-focus directive, but how can I implement it? <input type="search" ng-model="query"> <!--this is the button I need to show once th ...

Finding the Closest Element with jQuery's .closest() Method

I'm facing an issue while trying to select an element that is positioned above another element. Specifically, I want to target the nearest occurrence of the .discount-dropdown class that appears above the .discount-type class. Can anyone help me figur ...

Implementing transparency to clip-path using HTML and CSS

How can I apply opacity to the clip-path/clip area, similar to the image shown below? Please find my code snippet for reference: .item--clip .demo { width: 200px; height: 250px; } .item--clip .has-mask { position: absolute; clip: rect(10px, 19 ...

What is the best way to ensure that the child flex box matches the height of the parent flex box by 100%?

As a beginner, I'm venturing into creating an experimental site for myself. However, I am facing an issue where the .menu-container does not seem to stretch 100% the height of the .container. You can view the code on jsfiddle: https://jsfiddle.net/y1 ...

Angular's responsiveness is enhanced by CSS Grid technology

I am attempting to integrate a CSS grid template that should function in the following manner: Columns with equal width 1st and 3rd rows - 2 columns 2nd row - 3 columns https://i.sstatic.net/aQyNR.png Order = [{ details:[ { ke ...

Refusing to cease downloading music on the local server through the embedded audio element

I was trying to setup background music on my website, but when I test it localhost, the music download instead of playing. However, when I tested with the full path, it played as expected. How can I prevent the download from happening in localhost? Here i ...

Is it possible to utilize X-Y coordinates as repositories for values beyond just X-Y coordinates themselves?

I am in the process of creating a tile-based grid and I need to expand the X-Y coordinates to include additional values for determining characteristics of each tile, such as resources (for example, food, water, stone, lumber) within a game context. Conside ...