Opened 6 years ago

Closed 6 years ago

Last modified 5 years ago

#14582 closed (fixed)

django.contrib.staticfiles development file serving is backward-incompatible if MEDIA_URL was pointing to /static/ folder

Reported by: Mikhail Korobov Owned by: Jannis Leidel
Component: Contrib apps Version: master
Severity: Keywords: staticfiles
Cc: tkaemming Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

My project has these settings:

# settings.py
MEDIA_ROOT = os.path.join(PROJECT_PATH, 'static')
MEDIA_URL = '/static/'
#urls.py
if settings.DEBUG:
    urlpatterns += patterns('',
        (r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),
    )

after updating from django 1.2 to django trunk @14352 static files serving during development becomes broken: all requests to static files return 404 error now.

Attachments (1)

ticket-14582.diff (1.6 KB) - added by tkaemming 6 years ago.
Adds --nostatic option to "runserver" management command.

Download all attachments as: .zip

Change History (6)

comment:1 Changed 6 years ago by Karen Tracey

Triage Stage: UnreviewedAccepted

comment:2 Changed 6 years ago by Jannis Leidel

Owner: changed from nobody to Jannis Leidel
Status: newassigned

Changed 6 years ago by tkaemming

Attachment: ticket-14582.diff added

Adds --nostatic option to "runserver" management command.

comment:3 Changed 6 years ago by tkaemming

Cc: tkaemming added
Has patch: set

I've created a patch for this that adds a "--nostatic" option to the "runserver" management command which prevents the StaticFilesHandler from being loaded. If the option is not used, the StaticFilesHandler will be used (as it is currently on trunk at r14509).

This seems like a more appropriate solution than using django.conf.settings, since it only affects the "runserver" manage command.

If this patch needs additional tests or documentation, I'd be happy to help with that as well.

comment:4 Changed 6 years ago by Jannis Leidel

Resolution: fixed
Status: assignedclosed

(In [14533]) Fixed #14524, #14582, #14617, #14665 and #14667 -- Tweaked staticfiles app.

  • Updated StaticFilesHandler and AdminMediaHandler to make use of the 404 handler if needed.
  • Updated runserver management command to serve static files only in DEBUG mode (or if specified the --insecure option) and if the staticfiles app is in INSTALLED_APPS. Also added an option to disable serving completely (--nostatic).
  • Added check in debug mode if STATICFILES_* settings are different to MEDIA_* settings.
  • Removed a faulty PendingDeprecationWarning in AdminMediaHandler that is triggered every time runserver is used.
  • Fixed an issue with the modification time checks when running collectstatic.
  • Extended and refined documentation.

Thanks to everyone for input, especially to Carl Meyer, Ted Kaemming and
Adam Vandenberg for patches.

comment:3 Changed 5 years ago by Jacob

milestone: 1.3

Milestone 1.3 deleted

Note: See TracTickets for help on using tickets.
Back to Top