summaryrefslogtreecommitdiff
path: root/jinja2/filters.py
diff options
context:
space:
mode:
Diffstat (limited to 'jinja2/filters.py')
-rw-r--r--jinja2/filters.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/jinja2/filters.py b/jinja2/filters.py
index 0fb5a5a..cfe4594 100644
--- a/jinja2/filters.py
+++ b/jinja2/filters.py
@@ -510,13 +510,16 @@ def do_wordcount(s):
return len(_word_re.findall(s))
-def do_int(value, default=0):
+def do_int(value, default=0, base=10):
"""Convert the value into an integer. If the
conversion doesn't work it will return ``0``. You can
- override this default using the first parameter.
+ override this default using the first parameter. You
+ can also override the default base (10) in the second
+ parameter, which handles input with prefixes such as
+ 0b, 0o and 0x for bases 2, 8 and 16 respectively.
"""
try:
- return int(value)
+ return int(value, base)
except (TypeError, ValueError):
# this quirk is necessary so that "42.23"|int gives 42.
try: