DanH
DanH

Reputation: 5818

Django runserver with DEBUG True serving the wrong static files

Trying to server staticfiles via runserver for development, with Django 1.10

I have 'django.contrib.staticfiles' in my INSTALLED_APPS and the following relevant settings:

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

STATICFILES_DIRS = [
    path('node_modules'),  # resolves to `node_modules/` in the project root
]
STATIC_URL = '/static/'
STATIC_ROOT = path('static')  # resolves to `path/` in the project root

This works fine for collectstatic, and serves fine via NginX directly.

However with runserver + DEBUG=True, I'm expecting Django webserver to serve from the static/ folder, but instead it is serving from node_modules/ folder.

If I remove/rename node_modules/ then I get 404s for static files.

The static files are collected by copy (not symlink).

I'm using Django channels which could be hijacking everything as well?

Upvotes: 0

Views: 1635

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 600026

That is what the staticfiles app does: it wraps the built-in runserver command to serve static files directly from the source directories, so that there is no need to run collectstatic in development.

Edit You could disable the automatic handling by running runserver with the --nostatic flag, and point the static URL at your STATIC_ROOT manually:

from django.conf import settings
from django.conf.urls.static import static

if settings.DEBUG:
    urlpatterns += [
        static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
    ]

Upvotes: 2

Related Questions