Olivia Brown
Olivia Brown

Reputation: 642

How to use bootstrap styling in django project

I have downloaded bootstrap files (css, js) and put in the static folder of my project and made changes in header section of index.html as shown in the below code. But still django can't locate bootstrap.min.css as shown in the error

"GET /static/css/bootstrap.min.css HTTP/1.1" 404 1687

Project Structure

Project
|---Project
|---static
    |---css
    |---js
|---templates
    |---index.html
|---manage.py

index.html

<head>
{% load staticfiles %}
<link rel='stylesheet' href="{% static 'css/bootstrap.min.css' %}" type='text/css' />
</head>

I followed tutorials and read documentation But could not locate the problem can anybody help, thanks in advance.

Upvotes: 2

Views: 2434

Answers (2)

Errol
Errol

Reputation: 610

In your settings.py, should have BASE_DIR. It should look like this:

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

And add STATICFILES_DIRS at the end of your settings.py

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
)

Upvotes: 1

wrabbit
wrabbit

Reputation: 196

I'm not seeing anything wrong with your HTML or Project Structure.

Did you set STATICFILES_DIRS in your settings.py?

settings.py

# Add this at the end of your code if it isn't there already

STATICFILES_DIRS = [
    os.path.join("Project", "static"),
]

Upvotes: 2

Related Questions