Serving quasi-media files in production without cloud

Hello,

I have a client who wants a self-contained app on www.fly.io (no external cloud use, etc.). It is a variant of an image display application, where the images are uploaded from the admin side. End-users simply view the images. I wanted to learn Python, so I wrote the app in Django. It works fine in development, but I have not found a way to serve the images in production. Some details:

  • Fly.io offers “volumes”, an internal storage option that is seamlessly configured such that it operates like a local storage volume. The data on the volumes are backed up.
  • I have no access to a web server like Nginx. The serving of the images must be done through WSGI (in this case, gunicorn).

I have tried to accomplish this through Whitenoise, as follows:

# settings.py

WHITENOISE_USE_FINDERS = True
WHITENOISE_AUTOREFRESH = True

STATIC_URL = 'static/'
STATIC_ROOT = BASE_DIR / 'static_collected'

STATICFILES_DIRS = [
    '/data/media',
]

MEDIA_ROOT = '/data/media'
MEDIA_URL = '/media/'
# urls.py

...

urlpatterns += staticfiles_urlpatterns()
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

Whitenoise is serving the .css correctly. The images are being correctly uploaded to /data/media. But the images are not being served correctly in production!

My assumption was that by using these Whitenoise settings, and by adding /data/media to the STATICFILES_DIRS , the images would be served correctly. Any ideas? Is it even possible to serve image files this way on Django?

Thank you for your help, this is becoming a real headache!

(P.S. I did not change the STATIC_ROOT after adding WHITENOISE_USE_FINDERS and removing collectstatic from the Dockerfile, but the .css is still working fine.)