1

In the linked picture you can see the path to the css folder ,i tried to open the server . The html code works . But the css doesn't work . I think the problem is in the path . If yes , how to correct it ? I have no idea

<!DOCTYPE html>
<html>
  <head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <meta name="description" content="Crypto currency news">
  <meta name="keywords" content="bitcoin altcoin>
  <meta name="unknown" content="industry">
  <title>Acme News | About</title>
  <link rel="stylesheet" href="./css/style.css">
  </head>

image

user83869
  • 35
  • 7

2 Answers2

2

In django, you can manage static files by using {% static %}.

For using this, you have to set few things

  1. make sure django.contrib.staticfiles is included in INSTALLED_APPS

  2. Define STATIC_URL in settings.py

  3. In template, use static template tag. ({% load static %})

  4. load your static using {% static %}. i.e. {% static 'path/to/example.jpg' %}

Django official docs well explain about this. please check here

seuling
  • 2,850
  • 1
  • 13
  • 22
  • but thats not an image , i want to load css ! is this the same way for css ? – user83869 Jun 05 '18 at 06:06
  • Of course. That's how django manage static files - including css, js. Just add your css file in your `static` directory, (i.e. `static/css/style.css`) and call it by `{% static 'css/style.css' %}` – seuling Jun 05 '18 at 06:08
  • For beginner, it's little bit confusing to manage static files. (especially in dev environment.) I recommend read django docs for understanding correctly. – seuling Jun 05 '18 at 06:10
  • that helped alot – user83869 Jun 05 '18 at 06:16
  • html files should also be added to the static files ? – user83869 Jun 05 '18 at 06:19
  • Nope, you just add your `static` files. You can check about static files here(https://stackoverflow.com/questions/28918845/what-exactly-does-serving-static-files-mean-and-should-you-do-it). – seuling Jun 05 '18 at 07:59
-1

U should enter "../" to go to the previous folder.

<link rel="stylesheet" href="../css/style.css">
Shalin Nipuna
  • 450
  • 7
  • 14