hasherr hasherr - 1 year ago 95
HTML Question

Why won't Django load my static CSS files?

I'm having trouble getting Django to load my CSS for my html template. I'm aware that there are a lot of posts like this, such as here and here, but I'm not sure what else to do here as I've tried several of these types of these solutions to no avail.

Loading up my website using

python manage.py runserver
returns this log:

[31/Jul/2016 01:58:29] "GET / HTTP/1.1" 200 1703
[31/Jul/2016 01:58:29] "GET /static/css/about.css HTTP/1.1" 404 1766

I'm not sure if the 404 on the end of the second line of the log refers to a 404 error or not.

I have tried adding the static files to my

urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^$', TemplateView.as_view(template_name='about.html'))

urlpatterns += staticfiles_urlpatterns()

I have tried modifying my


STATIC_URL = '/static/'

STATICFILES_DIR = os.path.dirname(os.path.abspath(__file__)) + "/static/"


And I of course used the proper loading methods in the actual template itself:

{% load staticfiles %}
<link rel="stylesheet" href="{% static 'css/about.css' %}">

Here's my file structure:


Frankly, I'm not sure what else to do here. I feel like I've tried everything with the settings and still I'm getting that same log.

Answer Source

You should have this to serve static file in project directory...

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

os.path.dirname(os.path.abspath(__file__)) This is pointing to Personal_Website folder where settings all file is there...

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download