I am uploading a zip file through my form. How I can get the file size i.e in KB / MB so I can display it in my template.
I am uploading a zip file through my form. How I can get the file size i.e in KB / MB so I can display it in my template.
Django has a builti |filesizeformat template filter [Django-doc], you can thus use this with:
{{ file.size|filesizeformat }}
as the documentation says, this will:
Formats the value like a ‘human-readable’ file size (i.e.
'13 KB','4.1 MB','102 bytes', etc.).
You can solve this by using this custom template tag: https://djangosnippets.org/snippets/1866/
After then use it like this in your template:
{% load sizify %}
{{ yourFile.size|sizify }}
The file size will then be shown in a human readable format (kb, Mb, Gb)