Skip to content
Related Articles

Related Articles

Improve Article

Youtube video downloader using Django

  • Last Updated : 11 Jun, 2021

In this article, we will see how to make a YouTube video downloader tool in Django. We will be using pytube module for that.


 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course

  • pytube: It is python’s lightweight and dependency-free module, which is used to download YouTube Videos.
  • Django: It is python’s framework to make web-applications.

Here, we will be using Django as a backend along with pytube module to create this tool. We can install pytube module by typing the below command in the terminal.

pip install pytube

So, let’s dive in to make our YouTube video downloader tool.

First, we will create an HTML design (form) where the user can come and enter the URL of a video which he/she wants to download. We will use Django’s POST method to get that URL (because it is secure). We also need to use csrf token if we are using the POST method. Syntax for csrf token is: 

{% csrf_token %}


<!DOCTYPE html>
<h1>Youtube video downloader</h1>
<form action="" method="post">
  {% csrf_token %}
  <label for="link">Enter URL:</label>
  <input type="text" id="link" name="link"><br><br>
  <input type="submit" value="Submit">



Now, it’s time to create a function that receives the video link and downloads that video. You need to import function YouTube from module pytube in file.  Now we can define the function to download video.



# importing all the required modules
from django.shortcuts import render, redirect
from pytube import *
# defining function
def youtube(request):
    # checking whether request.method is post or not
    if request.method == 'POST':
        # getting link from frontend
        link = request.POST['link']
        video = YouTube(link)
        # setting video resolution
        stream = video.streams.get_lowest_resolution()
        # downloads video
        # returning HTML page
        return render(request, 'youtube.html')
    return render(request, 'youtube.html')



Now, we have to define the URL (path) for this function inside



from django.contrib import admin
from django.urls import path
from . import views
urlpatterns = [
    path('youtube',, name='youtube'),



That is it for the coding part, now you can run the project by python runserver and head over to http://localhost:8000/youtube to see the output.





When you click on submit a video will be downloaded in your Django project’s directory.


django youtube downloader


My Personal Notes arrow_drop_up
Recommended Articles
Page :