Open In App
Related Articles

Youtube video downloader using Django

Improve Article
Save Article
Like Article

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


  • 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


Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 25 May, 2022
Like Article
Save Article
Similar Reads
Complete Tutorials