Problem with deploying mp4 files in production

I have a problem serving MP4 and WEBM files in production. Everything works fine in development. I’m using a hosted server at Rochen which I’m pretty sure is a linux virtual server - uses

The video files are static files used in my home page and my help pages, embedded in the html. On the same html pages and in the same static folder are some gif files. The gif files display ok, but the video files give a 500 error in the browser and a “io.UnsupportedOperation: fileno” in the stderr.log

Extracts of the html are:

<div class="col-md-6 embed-responsive embed-responsive-4by3">
  <video class="border border-dark col-12 rounded-3 shadow" controls>
	<source src="{% static '/aerocoach/assets/home/home_01.mp4' %}" type="video/mp4"/>


Some of the relevant settings:

DEBUG = True
BASE_DIR = Path(file).resolve().parent.parent


STATIC_ROOT = BASE_DIR / “staticfiles”
STATIC_URL = “static/”

Myhome page shows the gif and the mp4 embedded.

GIF displays in a separate tab, but the mp4 doesn’t.


If I put in a wrong file name, then I get a django debug screen.


Django appears to be finding the mp4 file, but not rendering it. Is whitenoise corrupting the file?

Whitenoise is not corrupting the file once you always run python collectstatic, push to your GitHub, bitbuckets, and you had added the whitenoise middleware and STATICFILES_STORAGE you are good to go and looking at your you did add them.

The reason why your MP4 and WEBM files, Video files of course are not displaying in production is because they are media files which is not handled by your django-whitenoise in the production server.

You need to make that work via installing pip install django-storages and use any of your Django storage of your choice e.g., Amazon S3 buckets, and they are pretty easy to setup.

To setup your amazon storage, which is the one I use, kindly check this article:

How to Setup Amazon S3 in a Django Project (

For more info on Django-storages: check out this link:!&&p=f35c97f593d5b75dJmltdHM9MTY5NTY4NjQwMCZpZ3VpZD0wZmQ0MzE5ZC1mYTRlLTZmZjItMGUxOC0yMzVmZmI1MzZlZTgmaW5zaWQ9NTE5MA&ptn=3&hsh=3&fclid=0fd4319d-fa4e-6ff2-0e18-235ffb536ee8&psq=django+storages&u=a1aHR0cHM6Ly9weXBpLm9yZy9wcm9qZWN0L2RqYW5nby1zdG9yYWdlcy8&ntb=1

Goodluck dev!

I thought that MediaFiles were media files uploaded by a user and separated because Whitenoise loads the StaticFiles when the app starts.

Surely my handful of MP4 files are just static files? There will be less than ten files and will very rarely change and then, only if I am changing the “static” html for my home and help pages. Or does Whitenoise detect that the files are video and not serve them?

I don’t think that it’s worth the hassle of setting up django-storages and a third party provider just for a few video files.

Any suggestions for alternative methods?

I’m now trying to access a folder called “videofiles” at the root of my webserver ":

- aerocoach (my django application)
- videofiles

I’ve put my video file in there and trying to access as "",
but the django router is preventing access.

How do I write a url rule to allow access?

I’ve re-read the various docs on static and media files and I’m still a bit confused. I’m now trying put my video files into a mediafiles folder next to where my staticfiles are:


  • aerocoach
    • aerocoach(my application)
    • aerocoach_django(django, etc)
    • mediafiles
    • staticfiles

I’ve configured the settings to have:

MEDIA_ROOT = BASE_DIR / ‘mediafiles’
MEDIA_URL = ‘/media/’

I’ve also added the following to
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

I can now access the following in development:

But, I can’t access the file in production because I don’t think that I should be using “static” function in production.
The following url gives me a Django 404 error.

  1. Is this the correct approach or should the mediafiles and staticfiles folders be outside the application folder directly under public_html?

  2. How do I allow Django give me access to the “media” url in production? Do I add something to or is it a web server setting change to “.htaccess” or “”?

  3. How do I reference the media files in the front end? Is there a tag like {% static … %}?

I’m still struggling with serving video from my django server. See my previous post on this topic.

Can anyone give me a hint? My main problem is that Django is intercepting my media url call.

How do I allow Django give me access to the “media” url in production? Do I add something to or is it a web server setting change to “.htaccess” or “”?