To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/bfc1eb0d-8b69-4450-bfe0-7147ef729317%40googlegroups.com.--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/1603744A-A45A-4FDE-B5D6-3814CE589692%40gmail.com.
We already have the views, api, and logic around for finding and serving the correct files.
We could have staticfiles classes implement more complicated features like giving cache recommendations, and serving pre-gzipped files.
--
You received this message because you are subscribed to a topic in the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-developers/N0KbgDeLuUE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
2. Serving media files is a slightly different case. WhiteNoise was designed around the assumption that it's serving a set of developer-supplied, public files which remain unchanged during the lifetime of the process. This simplifies a lot of performance and security concerns that come with serving mutable, user-supplied files.
In my opinion one of the most important goals for Django is to make
deploying tiny projects securely and easily a trivial matter. We
aren't there right now.
import re
from django.conf import settings
from django.conf.urls import url
from django.contrib.staticfiles.views import serve as static_serve
from django.core.exceptions import ImproperlyConfigured
from django.views.decorators.cache import cache_control
from django.views.static import serve
def static(prefix, view=serve, **kwargs):
if not prefix:
raise ImproperlyConfigured("Empty static prefix not permitted")
if '://' in prefix:
return []
if not settings.DEBUG:
view = cache_control(max_age=86400 * 30)(view)
return [
url(r'^%s(?P<path>.*)$' % re.escape(prefix.lstrip('/')), view, kwargs=kwargs),
]
urlpatterns = static(settings.STATIC_URL, view=static_serve, insecure=True)
if settings.MEDIA_URL and settings.MEDIA_ROOT:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/db7e7fe6-c735-43bb-a3f7-2bc809707032%40googlegroups.com.
MIDDLEWARE_CLASSES = (...'whitenoise.middleware.StaticFilesMiddleware',...)
from private_media.storages import PrivateMediaStorage
class Car(models.Model):
photo = models.ImageField(storage=PrivateMediaStorage())
Regards,
Thomas.
https://docs.djangoproject.com/en/1.10/howto/static-files/ and https://docs.djangoproject.com/en/1.10/howto/static-files/deployment/.
If you need some help, I'm as available as I can be.
--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/9a6e143d-9bf9-4e26-89ca-cfc9944ba794%40googlegroups.com.
I'd like to work together with Dave to develop a proof of concept that integrates whitenoise into Django. I spent about an hour looking through whitenoise and our own static file serving code, and I think integrating whitenoise will yield a simpler user experience with about the same amount of code as have now.
Essentially, we'd recommend adding something like this to existing wsgi.py files (it would be in the default startproject template)
from whitenoise.django import DjangoWhiteNoise
application = DjangoWhiteNoise(application)
application.add_files(settings.MEDIA_ROOT, prefix=settings.MEDIA_URL)
which would have the benefit of working out of the box in production too, I think. Of course, you could disable that based on settings.DEBUG or some other toggle.
We could then deprecate:
* django/contrib/staticfiles/views.py
* django/contrib/staticfiles/management/commands/runserver.py
* django/contrib/staticfiles/handlers.py
* django/views/static.py
Any objections to doing further investigation in this area?