I am beginner with django.
On my website I would like to create a library which allows downloads of executable files which I created myself. I would like to count how many times each file has been downloaded.
I thought to use a middleware, knowing that I am able to make a middleware which counts and displays the number of times a page has been viewed :
def stats_middleware (get_response):
def middleware (request):
try :
p = Stat.objects.get(url = request.path)
p.views_number = F('views_number')+1
p.save
except Stat.DoesNotExist :
p = Stat.objects.create(url= request.path)
response = get_response(request)
response.content += bytes(
"cette page a été vue {} fois.".format(p.views_number),
"utf8"
)
return response
return middleware
I thought that if I managed to open the download in a new page, I could count the number of times it appears and thus the number of downloads of the file, but I did not manage to open the download in another tab.
How can I do this?