Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #2914: filesizeformat no longer dies on invalid values. Thanks,…

… dev@simon.net.nz

git-svn-id: http://code.djangoproject.com/svn/django/trunk@4044 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 92151b2d283ee46dfaf35ec93c41ffabce58e850 1 parent febe05b
@jacobian jacobian authored
Showing with 5 additions and 1 deletion.
  1. +5 −1 django/template/defaultfilters.py
View
6 django/template/defaultfilters.py
@@ -421,7 +421,11 @@ def filesizeformat(bytes):
Format the value like a 'human-readable' file size (i.e. 13 KB, 4.1 MB, 102
bytes, etc).
"""
- bytes = float(bytes)
+ try:
+ bytes = float(bytes)
+ except TypeError:
+ return "0 bytes"
+
if bytes < 1024:
return "%d byte%s" % (bytes, bytes != 1 and 's' or '')
if bytes < 1024 * 1024:
Please sign in to comment.
Something went wrong with that request. Please try again.