#34702: Runserver serving static files from STATICFILES_DIRS instead of 
STATIC_ROOT
-------------------------------------+-------------------------------------
               Reporter:  rmoscoe    |          Owner:  nobody
                   Type:  Bug        |         Status:  new
              Component:             |        Version:  4.2
  contrib.staticfiles                |       Keywords:  runserver,
               Severity:  Normal     |  staticfiles
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 This is my first Django project, so I apologize if this turns out not to
 be a bug--but I've done a lot of searching on Google, in the Django docs,
 and in the FAQ, and I am confident this is a bug. When I run
 collectstatic, my static files are correctly copied from the
 STATICFILES_DIRS directory to the STATIC_ROOT directory. However, when I
 run runserver, the static files are served from the STATICFILES_DIRS
 directory.

 I am attempting to serve a React front end with a Django back end, so I
 have run the build on the client side to generate static files for Django
 to serve. However, I was getting MIME Type errors for my CSS and JS files,
 despite getting a status code of 200 for them. In an attempt to resolve
 this issue, I changed the href and src attributes for the <link> and
 <script> tags in my index.html file in the STATIC_ROOT directory. However,
 I noticed that runserver was still looking for the CSS and JS files in the
 same place, which made me suspicious.

 With runserver still running, I started altering the href and src
 attributes for my <link> and <script> tags in my STATICFILES_DIRS
 directory (client/dist), and I saw the changes take effect in real time.
 The relevent settings in my settings.py file appear below:

 {{{
 STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')

 INSTALLED_APPS = [
     'django.contrib.admin',
     'django.contrib.auth',
     'django.contrib.contenttypes',
     'django.contrib.sessions',
     'django.contrib.messages',
     'django.contrib.staticfiles',
     'server.apps.ServerConfig',
     'rest_framework',
 ]

 MIDDLEWARE = [
     'django.middleware.security.SecurityMiddleware',
     'whitenoise.middleware.WhiteNoiseMiddleware',
     'django.contrib.sessions.middleware.SessionMiddleware',
     'django.middleware.common.CommonMiddleware',
     'django.middleware.csrf.CsrfViewMiddleware',
     'django.contrib.auth.middleware.AuthenticationMiddleware',
     'django.contrib.messages.middleware.MessageMiddleware',
     'django.middleware.clickjacking.XFrameOptionsMiddleware',
 ]

 STATIC_URL = '/static/'
 STATICFILES_DIRS = [os.path.join(BASE_DIR, 'client', 'dist')]
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34702>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/010701893419d019-5b7f25b2-404e-4402-a7b2-96a9b9df17f6-000000%40eu-central-1.amazonses.com.

Reply via email to