[Django] #34702: Runserver serving static files from STATICFILES_DIRS instead of STATIC_ROOT

21 views
Skip to first unread message

Django

unread,
Jul 8, 2023, 2:04:19 AM7/8/23
to django-...@googlegroups.com
#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.

Django

unread,
Jul 8, 2023, 5:55:30 AM7/8/23
to django-...@googlegroups.com
#34702: Runserver serving static files from STATICFILES_DIRS instead of STATIC_ROOT
-------------------------------------+-------------------------------------
Reporter: Ryan Moscoe | Owner: nobody
Type: Bug | Status: closed
Component: contrib.staticfiles | Version: 4.2
Severity: Normal | Resolution: invalid
Keywords: runserver, | Triage Stage:
staticfiles | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* status: new => closed
* resolution: => invalid


Comment:

I think you've misunderstood the expected behavior. From the
`STATICFILES_DIRS` [https://docs.djangoproject.com/en/dev/ref/settings
/#std-setting-STATICFILES_DIRS documentation]: "This setting defines the
additional locations the staticfiles app will traverse if the
FileSystemFinder finder is enabled, e.g. if you use the collectstatic or
findstatic management command or use the static file serving view."

In the future, it would be best to ask on the support channels
(TicketClosingReasons/UseSupportChannels) to confirm the bug, or at least
examine the code and point out what you think is at fault. Thanks.

--
Ticket URL: <https://code.djangoproject.com/ticket/34702#comment:1>

Reply all
Reply to author
Forward
0 new messages