html - Django doesn't load css files -
i testing django project locally. templates , static files listed:
static/ css/ js/ ... templates/ home.html ...
when run server, html file loaded firefox indicate that:
this xml file not appear have style information associated it. document tree shown below.
the html links in templates like:
<link rel="stylesheet" href="/static/css/bootstrap.min.css" type="text/css"/>
however, when input 127.0.0.1:8000/static/css/bootstrap.min.css in browser, file exists , can fetched.
[26/apr/2015 06:47:38]"get / http/1.1" 200 10125 [26/apr/2015 06:47:49]"get /static/css/bootstrap.min.css http/1.1" 200 117150
i have go through postings on topic, have done things below: settings.py have installed_apps:
installed_apps = ( 'django.contrib.admin', ... 'django.contrib.staticfiles', 'frontend', 'crawler', }
my urls.py pasted here:
from django.conf.urls import patterns, include, url django.contrib import admin django.contrib.staticfiles.urls import staticfiles_urlpatterns urlpatterns = patterns('', url(r'^$', include('frontend.urls')), ); urlpatterns += staticfiles_urlpatterns()
what problem here?
in urls.py file,
from django.conf.urls import patterns, include, url django.contrib import admin django.contrib.staticfiles.urls import staticfiles_urlpatterns urlpatterns = patterns('', url(r'^$', include('frontend.urls')), ); urlpatterns += static(settings.static_url,document_root=settings.static_root)
make sure settings.py file has these defined.
base_dir = os.path.dirname(os.path.dirname(__file__)) static_url = '/static/' static_root = os.path.join(base_dir, '../static') staticfiles_finders = ( 'django.contrib.staticfiles.finders.appdirectoriesfinder', 'django.contrib.staticfiles.finders.filesystemfinder', )
also, in templates add on top:
{%load staticfiles%}
these settings work me.
Comments
Post a Comment