Reputation: 506
I have set up Django with bootstrap following some tutorials but even when I am doing the same as in the tutorials Django doesn't find the static files.
My Project has the following structure:
webshop
shop
migrations
templates
...
static
css
bootstrap.min.css
...
webshop
...
db.sqlite3
manage.py
In the data settings.py I have added
STATIC_URL = '/static/'
And in the Index.html I load the static files with following code:
<head>
<title>Webshop</title>
{% load staticfiles %}
<link rel="stylesheet" href="{% static 'css/bootstrap.min.css' %}" type="text/css"/>
</head>
But Django can't find the data bootstrap.min.css.
Upvotes: 1
Views: 4138
Reputation: 359
As per Django documentation you should specify the folder when the static file is not tied to a specific app:
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"),
'/var/www/static/',
]
https://docs.djangoproject.com/en/1.11/howto/static-files/
In your case it could be:
STATIC_URL = '/static'/
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"),
'/path/to/webshop/static',
]
Also please pay attention in the @kiran.koduru comment above regarding {% load static %}
. This is the right way to load static files in Django templates.
Upvotes: 2
Reputation: 90
in your HTML code add
{% load static %}
and your setting.py add
STATIC_URL = "/static/"
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
Upvotes: 3