Git Product home page Git Product logo

Comments (3)

evansd avatar evansd commented on September 7, 2024

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.

from whitenoise.

vstoykov avatar vstoykov commented on September 7, 2024

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.

from whitenoise.

evansd avatar evansd commented on September 7, 2024

@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.

from whitenoise.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.