Opened 8 years ago
Last modified 8 months ago
#27325 new New feature
Offer a solution for static file serving suitable for production use
Reported by: | Tim Graham | Owned by: | |
---|---|---|---|
Component: | Core (Other) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Aleksej Manaev, Ülgen Sarıkavak | Triage Stage: | Accepted |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
The documentation for the function for serving static files, django.contrib.staticfiles.views.serve()
, describes it as "grossly inefficient and probably insecure. This is only intended for local development, and should never be used in production." To ease the deployment of small sites, it would be nice to fix or replace it with something that could be used in production. WhiteNoise is an example of static file serving done in Python and is a possible candidate for integration in Django.
Ideas are discussed in more detail on the delegating our static file serving thread on django-developers.
Change History (9)
comment:1 by , 8 years ago
Cc: | added |
---|---|
Owner: | changed from | to
Status: | new → assigned |
comment:2 by , 8 years ago
Description: | modified (diff) |
---|
comment:3 by , 8 years ago
Has patch: | set |
---|
comment:4 by , 8 years ago
Patch needs improvement: | set |
---|
I agree with what Florian said on the mailing list, "I think there is no need to vendor [whitenoise], we can just depend on it. (like we do for pytz)". The Django-specific parts can be moved in Django. Also, Python 2 compatibility can be removed since the master branch doesn't support it anymore. Tests and documentation are also required.
comment:5 by , 8 years ago
If we deprecate django.contrib.staticfiles.handlers.StaticFilesHandler and replace it by DjangoWhiteNoise in django.contrib.staticfiles.testing.StaticLiveServerTestCase it would not be possible to run tests without using collectstatic first. Is this an important behavior?
tests/staticfiles_tests/test_liverserver.StaticLiveServerView.test_collectstatic_emulation only passes with DEBUG=True.
WHITENOISE_USE_FINDERS=True causes:
"django.core.exceptions.ImproperlyConfigured: WHITENOISE_USE_FINDERS can only be enabled in development when WHITENOISE_AUTOREFRESH is also enabled."
EDIT:
Now I do not get errors using WHITENOISE_USE_FINDERS=True and WHITENOISE_AUTOREFRESH=True which can be used in StaticLiveServerTestCase to achieve running tests without collectstatic first.
See:
- tests/staticfiles_tests/test_liverserver.StaticLiveServerViewUseFinders.test_collectstatic_emulation
- tests/staticfiles_tests/test_liverserver.TestWhitenoiseMiddlewareUseFinders.test_collectstatic_emulation
Does anybody know why overriding_settings within a test method has no effect?
For example:
with self.settings(WHITENOISE_USE_FINDERS=True, WHITENOISE_AUTOREFRESH=True): response = self.client.get('/static/test/file.txt') content = b'' for item in response.streaming_content: content += item self.assertEqual(content.rstrip(b'\r\n'), b'In static directory.')
comment:6 by , 8 years ago
Patch needs improvement: | unset |
---|
comment:7 by , 8 years ago
Patch needs improvement: | set |
---|
comment:8 by , 2 years ago
Has patch: | unset |
---|---|
Owner: | removed |
Patch needs improvement: | unset |
Status: | assigned → new |
comment:9 by , 8 months ago
Cc: | added |
---|
Pull Request: https://github.com/django/django/pull/8245