Okay, all. I know this is a question that many people have solved in various cases, but I cannot for the life of me get my Django 1.9 development server to serve static content on my local computer. Static files worked fine pre-deployment, and are totally fine on my deployment server, but now in my test environment (local computer with runserver
going) everything is broken, and I really need to be able to test stylesheets in a dev environment.
I have tried all of these solutions and more, followed the documentation guide, used collectstatic
again in the development repo... nothing has worked, and I am at my wits' end.
Currently, I have DEBUG = True
, and the following setup:
Folder Hierarchy
project/
manage.py
(&c)
app/
urls.py
models.py
(&c)
project/
settings.py
urls.py
(&c)
static/
styles/
images/
(&c)
settings.py Static Files Settings
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATICFILES_DIRS = (
os.path.join(STATIC_ROOT, 'styles/'),
os.path.join(STATIC_ROOT, 'js/'),
os.path.join(STATIC_ROOT, 'audio/'),
os.path.join(STATIC_ROOT, 'images/'),
os.path.join(STATIC_ROOT, 'admin/'),
os.path.join(STATIC_ROOT, 'documents/'),
)
urls.py URL Patterns
from django.conf.urls import include, url, patterns
from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
urlpatterns = [
# ... project url patterns blah blah ...
]
if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += patterns('', (r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root':settings.STATIC_ROOT, 'show_indexes': True}))
I also have {% load staticfiles %}
in my templates along with the appropriate {% static %}
calls (ex: {% static 'styles/main.css' %}
).
For reference, the command line gives me the following when I load the page:
"GET /static/styles/main.css HTTP/1.1" 404 1759
If anyone knows of a fix I have missed that might even remotely have a snowball's chance of working, please let me know. It's driving me bonkers not being able to test properly.
EDIT: As suggested, I have updated to Django 1.11 on my local machine, with no changes to the current issue.