How to upload videos in Django – Django tutorials

how to upload videos in Django - django tutorial - www,

Hello, welcome to another great tutorial in Django. In this tutorial, you will learn how to upload videos in Django. I hope this tutorial definitely helps you in your Django projects or ideas.

What you learn here

  • Create a model for Vidoes
  • Upload a videos from admin panel
  • Creating views for display and upload videos
  • Upload videos from Templates ( HTML Pages )

Let’s build the video uploading project in Django. If you don’t know how to start a Django project and start a Django app please follow these links.

Required knowledge

Build a video uploading project in Django

I created a new app called “video_content“, add it in the file.


Now configure the static files, templates and media files in file. And also configure them in file to work media files and static files properly.



'DIRS': [os.path.join(BASE_DIR,'templates')],



STATIC_URL = '/static/'

    os.path.join(BASE_DIR, "static") 

STATIC_ROOT = os.path.join(BASE_DIR,'assets')


MEDIA_URL ='/media/'

MEDIA_ROOT = os.path.join(BASE_DIR,'media')

Now configure the file.

from django.urls import path
from video_content.views import upload_video,display

from django.conf.urls.static import static
from django.conf import  settings

urlpatterns = [


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

You must create the media folder, static folder, and template folder outside of the project folder.

1. Create a model for videos uploading in Django

Now we need to create a model for uploading videos and save them in the database. Here I created a few fields, you can add more fields according to your project.

from django.db import models

# Create your models here.

class Videos(models.Model):
    title = models.CharField(max_length=100)
    video = models.FileField(upload_to='videos/')
    class Meta:
        verbose_name = 'video'
        verbose_name_plural = 'videos'
    def __str__(self):
        return self.title

Now its time to migrate our model and create superuser to access the admin panel. and also register the video model in the file.

To migrate the video model and create a superuser execute the below commands in cmd or terminal.

2. Upload videos from Django Admin

python makemigrations

python migrate

python createsuperuser

# Enter your credintials to register as admin.

python runserver

Now add a Video model in the file to register our model.

from django.contrib import admin

# Register your models here.
from .models import Videos

Now login to your Django admin panel and upload a video.

3. Creating views to upload and display videos

Now its time to create the views for uploading and display the videos in the HTML pages. copy and paste the code

from django.shortcuts import render,redirect

from .models import Videos

# Create your views here.

def upload_video(request):
    if request.method == 'POST': 
        title = request.POST['title']
        video = request.POST['video']
        content = Videos(title=title,video=video)
        return redirect('home')
    return render(request,'upload.html')

def display(request):
    videos = Videos.objects.all()
    context ={
    return render(request,'videos.html',context)

Here we create a display and upload_video views to display all the videos and upload the videos from the user end. we already configure the views in file.

4. Creating Templates to upload and display videos

Now create the templates videos.html and upload.html files in the template folder. You must follow the same template names which we added in views.


<form action="" method="POST">{% csrf_token %}

    <input type="text" name="title" placeholder="Enter Video Title here"><br>
    <input type="file" name="video" accept="video/*">
    <button type="submit"> Upload New Video </button>


Here we restrict the user to upload video in the .mp4 format only from the front end using accept attribute.


let’s show the all the videos in our Database which were uploaded by us.


{% for video in videos %}
<video width="500" height="500" controls >
<source src="{{}}" type="video/mp4">


Now run the server to upload a video from the HTML pages using the following command in cmd or terminal.

python runserver

Now enter the URL according to the file in the browser.

Here you can upload .mp4 format video and click on the upload New Video Button to upload it to the database.

Once you complete the video uploading processing then now run the other URL videos in the browser to view our videos.

If you play the video, then it will look like below. Let’s play the videos, Enjoy!

You can do more customizations and stylings and colorings to the front-end, but I gave the good functionality to work with videos uploading in Django.


Successfully we are done uploading videos in the Django project. I hope this tutorial will help you a lot. To read more read the docs.

If you have any doubts please comment below and to get more notification on our python Django tutorials and machine learning tutorials to subscribe to our newsletter for Free.

5 thoughts on “How to upload videos in Django – Django tutorials”

Leave a Reply