Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serving media files #32

Closed
moonstruck opened this issue May 23, 2015 · 3 comments
Closed

Serving media files #32

moonstruck opened this issue May 23, 2015 · 3 comments

Comments

@moonstruck
Copy link

Is there any option in DjangoWhiteNoise to serve media files like MediaCling of dj-static?

@evansd
Copy link
Owner

evansd commented May 23, 2015

I'm afraid not. WhiteNoise is optimized to serve a small set of files that remain fixed while the application is running, and it wouldn't work well for this purpose. I think most people using WhiteNoise use Amazon S3 to store and serve their media files.

If you just want to serve media files in development then I've used a pattern like this in my urls.py file:

if settings.SERVE_MEDIA_FILES:
    urlpatterns += patterns('',
        url(r'^%s(?P<path>.*)$' % settings.MEDIA_URL.lstrip('/'),
            'django.views.static.serve',
            {'document_root': settings.MEDIA_ROOT}),)

And then in development I have SERVE_MEDIA_FILES = True.

@evansd evansd closed this as completed May 23, 2015
@vstoykov
Copy link

vstoykov commented Jan 7, 2016

Actually WhiteNoise can be used to serve media files. Probably it's not optimal but still if you use some sort of CDN you can put in your wsgi.py file the following code:

from django.conf import settings
from whitenoise import WhiteNoise
from whitenoise.django import DjangoWhiteNoise

application = WhiteNoise(
    DjangoWhiteNoise(get_wsgi_application()),
    root=settings.MEDIA_ROOT,
    prefix='/media/',
)

Prefix is hardcoded because if you use CDN you can can configure your MEDIA_URL to be absolute URL of the CDN.

@evansd
Copy link
Owner

evansd commented Jan 7, 2016

@vstoykov I'm afraid this won't work how you expect it to. WhiteNoise scans for available files on startup and assumes that they won't change for the lifetime of the process. So any new files that get uploaded while the app is running won't get served.

glogiotatidis added a commit to glogiotatidis/KickIt that referenced this issue Dec 1, 2018
This doesn't work b/c whitenoise causes available files on startup. See
evansd/whitenoise#32 (comment)

This reverts commit 0008294.
iokouts pushed a commit to iokouts/KickIt that referenced this issue Dec 1, 2018
This doesn't work b/c whitenoise causes available files on startup. See
evansd/whitenoise#32 (comment)

This reverts commit 0008294.
iokouts pushed a commit to iokouts/KickIt that referenced this issue Dec 25, 2018
This doesn't work b/c whitenoise causes available files on startup. See
evansd/whitenoise#32 (comment)

This reverts commit 0008294.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants