#------------- static_root_finder.py -------------------#
from django.contrib.staticfiles.finders import BaseFinder
from django.conf import settings
import os
class StaticRootFinder(BaseFinder):
def __init__(self, apps=None, *args, **kwargs):
super(StaticRootFinder, self).__init__(*args, **kwargs)
def find(self, path, all=False):
"""
Looks for files in the extra locations
as defined in ``STATIC_ROOT``.
"""
abs_path = os.path.join(settings.STATIC_ROOT, path)
if os.path.exists(abs_path):
return abs_path if not all else [abs_path]
return []
#------------- urls.py -------------------#
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
#
# Your urls.py file
#
urlpatterns += staticfiles_urlpatterns()
#------------- settings.py -------------------#
STATICFILES_FINDERS = (
'static_root_finder.StaticRootFinder',
)
Comments
This is ass-backward,
STATIC_ROOTisn't supposed to be served directly in development mode.Just follow the basic usage docs and add a separate (different from
STATIC_ROOT) directory toSTATICFILES_DIRSto serve it (e.g for 'project' files).#