Phob1a
Phob1a

Reputation: 773

Can't load static files in DJango

I'm trying to load the css files in Django from myapp/static/myapp/css but I can't get it to work. Chrome console says it couldn't get the files (404).

Settings.py:

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

...

STATICFILES_FINDERS = (
    "django.contrib.staticfiles.finders.FileSystemFinder",
    "django.contrib.staticfiles.finders.AppDirectoriesFinder",
)

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

STATIC_ROOT = ''
STATIC_URL = '/static/'

urls.py:

urlpatterns = patterns('',
    url(r'^admin/', include(admin.site.urls)),
    url(r'^projects/', include('projects.urls', namespace='projects')),
    url(r'^home/', include('home.urls', namespace='home')),

)+static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns += staticfiles_urlpatterns()

home urls.py:

from django.conf.urls import patterns,url
from projects.views import DetailView, ListView

urlpatterns = patterns('',
    url(r'^(?P<pk>\d+)/$', DetailView.as_view(), name='detail'),
    url(r'^$', ListView.as_view(), name='list'),
)

base.html:

    <link href="{% static 'home/css/bootstrap.min.css' %}" rel="stylesheet" media="screen">
    <script src="{% static 'home/js/jquery-2.1.1.min.js' %}" type="text/javascript"></script>  

Upvotes: 1

Views: 4813

Answers (1)

Phob1a
Phob1a

Reputation: 773

I found out the code works perfectly well. The problem was that I forgot to put the home app in INSTALLED_APPS.

Thanks for your time.

Upvotes: 3

Related Questions