diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py index b0cfcfdeb9..a95a5dff6f 100644 --- a/django/template/defaultfilters.py +++ b/django/template/defaultfilters.py @@ -141,6 +141,8 @@ def upper(value): def urlencode(value): "Escapes a value for use in a URL" import urllib + if not isinstance(value, basestring): + value = str(value) return urllib.quote(value) def urlize(value): diff --git a/tests/regressiontests/defaultfilters/tests.py b/tests/regressiontests/defaultfilters/tests.py index 481557b782..b4ec9a0b03 100644 --- a/tests/regressiontests/defaultfilters/tests.py +++ b/tests/regressiontests/defaultfilters/tests.py @@ -111,6 +111,8 @@ u'\xcb' >>> urlencode('jack & jill') 'jack%20%26%20jill' +>>> urlencode(1) +'1' >>> urlizetrunc('http://short.com/', 20)