Django looks in `templates` when loading static file

I am new to Django and I have the following issue: when I try lo link my layout.html to styles.css Django looks in the wrong place. The layout.html code which reads:

{% load static %}

<!DOCTYPE html>

<html lang="en">

<head>
    <title>{% block title %}{% endblock %}</title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
    <link href="{% static 'encyclopedia/styles.css' %}" rel="stylesheet">
    
</head>

and the structure of my encyclopedia dir is as follows:

├── db.sqlite3
├── encyclopedia
│   ├── __init__.py
│   ├── __pycache__
│   ...
│   ├── models.py
│   ├── static
│   │   └── encyclopedia
│   │       └── styles.css
│   ├── templates
│   │   └── encyclopedia
│   │  ...     └── search.html
│   ├── tests.py
│   ├── urls.py
│   ├── util.py
│   └── views.py
├── manage.py
└── wiki

I did check the settings.py file in dir wiki and it does have a: STATIC_URL = '/static/' line. Yet Django keeps looking in templates as per the following error message: error message from VS Code

Can anyone tell me what I am doing wrong?

Upvotes: 0

Views: 61

Answers (1)

Synthaze
Synthaze

Reputation: 6090

There was a type in your code in the href (% right missing)

{% load static %}

<!DOCTYPE html>

<html lang="en">

<head>
    <title>{% block title %}{% endblock %}</title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
    <link href="{% static 'encyclopedia/styles.css' %}" rel="stylesheet">
    
</head>

Upvotes: 1

Related Questions