The issue with Django where HTML links are pointing to an incorrect directory for the CSS files

On my main page, the URL localhost:8000/helloworld/greeter can be found at helloworld\templates\hello:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8"/>
        <title>Hello!</title>
        {% load static%}
        <link rel="stylesheet" type = "text/css" href = "{% static 'hello/site.css' %}" />
    </head>
    <body>
        <span class="message">Hello there, {{ name }}!</span> It's {{ date | date:'l, d F, Y' }} at {{ date | time:'H:i:s' }}.
    </body>
</html>

The accompanying CSS file is located at helloworld\static\hello (so it should look for localhost:8000\helloworld\static\hello\site.css):

.message{
    font-weight
    color: blue;
}

Reviewing the file structure reveals this layout: https://i.sstatic.net/qzNI5.png

The expected outcome was to have the phrase "Hello there, [name]" in bold and blue. However, the actual result presents a different appearance as displayed here: (this is the issue) https://i.sstatic.net/A6P6S.png Further investigation in the console offers the following error message:

GET http://localhost:8000/static/hello/site.css net::ERR_ABORTED 404 (Not Found)

It appears that the directory "static" is being referenced incorrectly, assuming it is at the root instead of within localhost\helloworld.

A solution needs to be identified to rectify this matter and ensure the correct directory linkage.

An attempt was made to modify the block, specifically:

<link rel="stylesheet" type = "text/css" href = "{% static 'hello/site.css' %}" />

This change was implemented:

<link rel="stylesheet" type = "text/css" href = "{% 'helloworld/static/hello/site.css' %}" />

There was an expectation for site.css to be applied, but rather than success a TemplateSyntaxError was encountered.

Answer №1

The issue has been resolved by following these steps:

Within the settings.py file, I modified the line to read as

STATIC_URL = '/salutations/static/'

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

Adjust the paragraph font size within the bootstrap stylesheet

We currently utilize the bootstrap v2 CSS and are interested in globally increasing the font size by a point or two. I am wondering if this adjustment is a straightforward modification within the CSS file or if it requires a more complex approach. After a ...

Tips on overriding the outline:none property in CSS

Is there a way to overwrite the 'outline: none' property in CSS? I have a parent class that has this property set, but I want to remove it in the child class. ...

Simplify webpage to display only text content using iOS (Objective C)

My main objective is to replicate the functionality of Readability or Safari's Reader service, where the primary content of a webpage is converted to text. I do not intend to display any images, only to extract the important text from the webpage. Cur ...

Creating a table with four cells per row in HTML using AngularJS - step by step guide

I am tasked with creating a table where the first cell in each row displays the name of a store, and the subsequent cells display the names of terminals associated with that store. The current layout is shown below. Each store has a list of terminals. ...

Adjust the size of my navigation bar to match the dimensions of the browser

I'm currently facing an issue with my website's navigation menu on mobile devices. I've been attempting various solutions to make the navigator scale up appropriately with the browser, but so far nothing seems to be working. Below is the HT ...

Is it possible to create a basic textarea with minimal height-rows but fill 100% of the height?

Within my div, there is a textarea element that I am having trouble sizing correctly vertically. The container div is set to the right size (100%), but I need to give the textarea a minimum height or number of rows to enable scrolling if needed, while sti ...

Error in Django: AttributeError - the object does not have the attribute '__state'. This issue can be resolved by deleting the '__init__' method from the

I'm currently in the process of developing a model for a Django application called "webshop", but I seem to be struggling with identifying the root cause of my issues. Here is my models.py file: from django.db import models class Product(models.Mode ...

Combine several svg elements within a single div row using Bootstrap 5

Is there a way to adjust the SVG settings in order to have two of them side by side within a div class="col" element? ...

Personalize the Bootstrap 4 CDN option

Is there a mistake in my code or am I just missing something when trying to override Bootstrap 4 CSS/SCSS? I tested it on W3Schools and it worked, but it doesn't seem to be working elsewhere. Additionally, I prefer to serve different CSS files to user ...

Dealing with multiple modal dialogs in Bootstrap

I am attempting to work with two separate modal dialogs within Twitter Bootstrap. My approach involves duplicating the HTML code for the modal dialog and creating a new button (BTN2) with data-toggle="modal2". When the new button (BTN2) is clicked, the se ...

Tips for personalizing the react-select module

I'm struggling with customizing the appearance of the react-select component. The official documentation lists all the style attributes that can be modified, but I'm having trouble removing the blue borders around the text and container. https:/ ...

Altering the value of a global variable through a local function in JavaScript

I have developed a straightforward piece of Java script code. I'm looking to update the value of a global variable using a local function. Whenever I trigger the value1() function, I want the output to display as "2". Is there a way I can achieve this ...

Checkbox Selection - Modify Prompt to "Kindly mark this box to continue"

I have created a multi-select checkbox form, and I've added some JavaScript to ensure that the visitor selects at least one option <div class="form-group options"> <label class="control-label col-md-4" for="optiontext">Specify an option&l ...

What is causing the background image size to adjust when the carousel is toggled?

Can you help me understand why the background-image increases in size vertically when transitioning from url/path to url/path2? I need it to stay the same size as it toggles through all the images. What mistake am I making and how can I correct it? Snipp ...

Icon appearing outside the button instead of inside

Here's a button I'm working with: <button class="glyphicon glyphicon-option-horizontal" (click)="myFuncion()"></button> Recently, I updated my bootstrap library from version 3 to 4.2.1 and now the icon is no longer visible. I' ...

How can I omit spaces in the HTML output when saving a data frame using to_html?

After using the to_html method, I noticed that there are \n after > and spaces before <. Is there a way to prevent them from being saved? Here is an example of what I have: <table border="1" class="dataframe"> <t ...

The resulting line will consist of the discovered string

Let's say there's an interesting HTML document presented below with associated line numbers: 30 - <div id="myDiv"> 31 - <span class="mySpan">Some Text</span> In this scenario, PHP is being utilized for a specific purpose: $ ...

Retrieving PHP information in an ionic 3 user interface

We are experiencing a problem with displaying data in Ionic 3, as the data is being sourced from PHP REST. Here is my Angular code for retrieving the data: this.auth.displayinformation(this.customer_info.cid).subscribe(takecusinfo => { if(takecusi ...

When a website is deployed to an application, the process includes MVC bundling and managing relative CSS image paths

When trying to convert relative image paths to absolute paths, there are numerous queries on stackoverflow addressing this issue. For example, take a look at this thread: MVC4 StyleBundle not resolving images This question recommends using new CssRewrite ...

Repeating percentages displayed in a progress bar

I created a responsive progress bar, but the progress values are repeating. I only want the central value to be displayed. Any suggestions on how to fix this issue? DEMO <div id="tab1"> <dx-data-grid class="tableTask" [dataSource]="datas" ...