ryan
ryan

Reputation: 645

Cannot locate CSS static files for Django page

enter image description here

I'm currently trying to get the styles to load for my index page and am not having any luck. The above illustrates my current file structure. DEBUG = True and I have run collectstatic to no avail. I'm assuming it's all a basic directory mapping issue, but can't seem to figure it out. Thanks in advance.

settings

STATIC_URL = '/static/'

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

URLS

from django.conf.urls import include, url
from django.contrib import admin
from homepage.views import main_page
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [

    url(r'^$', main_page, name = 'home'),
    url(r'^admin/', include(admin.site.urls)),

] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

html snippet

{% load staticfiles %}
<link href="{% static 'css/style.css' %}" rel="stylesheet">
<link href="{% static 'css/font-awesome.min.css' %}" rel="stylesheet">
<link href="{% static 'css/bootstrap.css' %}" rel="stylesheet">

ERROR

'static/css/bootstrap.css' could not be found

Upvotes: 0

Views: 63

Answers (1)

rnevius
rnevius

Reputation: 27112

You're confusing a couple of staticfiles topics.

First, you need to define STATICFILES_DIRS in your settings.py. This needs to be different than your STATIC_ROOT (which doesn't need to be set in development with DEBUG = True):

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

If you want to define STATICFILES_ROOT, this needs to be different than the above. The STATICFILES_ROOT is the location where collectstatic will "collect" static files from your STATICFILES_DIRS, for production.

Upvotes: 2

Related Questions