Upload videos with proper seekbar in Django

Sneha Veerakumar
2 min readMar 29, 2021

--

  1. Analysing the problem with seekbar of uploaded videos.
  2. Solution : Configuring wsgi.py file.

Assuming that you have already set up your application for the django project and found an issue where uploaded videos do not have a proper seekbar. This article will help you to resolve this issue.

Analysing the problem with seekbar of uploaded videos

You need to implement HTTP byte ranges in Django to accept the requested range and respond with a HTTP 206 Partial Content response.

wsgi.py file is an entry-point for WSGI-compatible web servers to serve your project. This is the file which you need to configure such that your application provides partial content of the video.

To do this we need a middleware utility which serves static assets from production with a WSGI server. We also need to serve templated content through WSGI such that it handles HTTP byte ranges and displays the video with proper seekbar.

Solution : Configuring wsgi.py file.

We do not need to write middleware utility and static-ranges from scratch as we can install it from the following command line.

pip install dj-staticpip install static-ranges

Now we need to configure the entry point, wsgi.py file such that it serves partial contents of the video.

wsgi.py file before configuration :

import osfrom django.core.wsgi import get_wsgi_applicationos.environ.setdefault('DJANGO_SETTINGS_MODULE', 'djangoblog.settings')application = get_wsgi_application()

wsgi.py file after configuration :

import osfrom static_ranges import Rangesfrom django.core.wsgi import get_wsgi_applicationfrom dj_static import Cling, MediaClingos.environ.setdefault('DJANGO_SETTINGS_MODULE', 'sample.settings')application = Ranges(Cling(MediaCling(get_wsgi_application())))

Initially to use dj-static, we write a sentence “ application = Cling(get_wsgi_application()) ”. We further add Ranges() from static ranges which completes the configuration of file to respond topartial content.

“ application = Ranges(Cling(MediaCling(get_wsgi_application())))” uses both utilities and provides the solution to our problem.

--

--

Sneha Veerakumar
Sneha Veerakumar

Written by Sneha Veerakumar

Technical content writer at GeeksforGeeks. Sophomore at Vellore Institute of Technology.

No responses yet