Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

My html isn't connecting to my css only when running trought server

I am making a Django app and when I try to run the different pages the HTML is loading but not the CSS, when I open the files normally (not from the server) it all works fine, but when I run them through the server it searches for the CSS at the URL page. Here is an example:
at URL:http://127.0.0.1:8000/profile/create/
the HTML is all working but CSS isn’t and I get this in the terminal:

[21/Dec/2022 10:11:54] "GET /profile/create/ HTTP/1.1" 200 1374
Not Found: /profile/create/style.css
[21/Dec/2022 10:11:54] "GET /profile/create/style.css HTTP/1.1" 404 2993

The HTML and CSS are in the same directory and here is my connection from my HTML

    <!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" type="text/css" href="style.css">
    <title>MyPlantApp</title>
</head>

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You need to create a folder for your static files and store all your static files there.
set your static files directory using this code in your settings.py file

STATICFILES_DIRS = [
(os.path.join(BASE_DIR, "static/")),

]

your static folder should look like this
static file folder
Also you need to use the proper templating syntax to specify find your static files.
change
<link rel="stylesheet" type="text/css" href="style.css">
to
<link rel="stylesheet" type="text/css" href="{% static 'style.css' %}">

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading