Skip to content
Advertisement

How to track download link in django?

I followed these method to track how much downloaded the file was. But total_downloads always remains same (it’s 0). How to increment total_downloads field by 1 after every download?

My models.py:

JavaScript

views.py. In this program, I want to increment the number of downloads. But it’s 0 in admin site.

JavaScript

urls.py

JavaScript

index.html from where people can download the file

JavaScript

Advertisement

Answer

Try using Axios to download the file,

In the template, Try this-

JavaScript

Now in the backend, create a route for /post-downloaded/

In your urls.py file-

JavaScript

And in the views.py file create this-

JavaScript

This should get the work done

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement