File Upload Progress Bar Using Django and Ajax

Anshu Pal
2 min readJul 29, 2021
Django with Ajax

In this tutorial, we gonna learn how we can create a file upload progress bar in Django.

Django allows you to create a server where you can upload a file or any media, but the problem with this approach is that Django will upload the file as a whole and reload the page once the upload is complete which forces the user to do an only a single task.

By the way, if u want, a detailed video is on youtube for this tutorial.

Imagine you have to upload a file of 1 GB and until the file is uploaded you cannot navigate to any other page, you have to just wait and let the upload finishes.

To overcome this issue we gonna use Ajax and also show users the progress of the file that is being uploaded. I have already explained in the previous tutorial, what Ajax is and how it can be used with Django.

So let’s get started with the coding part.

We will create a simple model and have the image field in the model.

This is a simple model with just two fields

Now let’s create a form for this model

Now that our form is ready, let’s render this form in our templates, so inside view.py type the following code

At last, let's make an Ajax call to the server when the user hits the upload button and also render the form obviously.

That’s it, that is all you have to do.

For a detailed tutorial checkout the Youtube Video.

Cheers

Happy Coding

--

--

Anshu Pal

I’m a web developer. I spend my whole day, practically every day, experimenting with HTML, CSS, and JavaScript.