From the Django source, urlencode
is basically a wrapper around Django's urlquote
utility method. From the comments in the source, urlquote
is a UTF-8-safe version of urllib.quote
.
So urlencode
is using the same defaults as python's urllib.quote
, and the reason that urllib.quote
does not escape slashes can be found in the documentation:
Replace special characters in string using the %xx escape. Letters,
digits, and the characters '_.-' are never quoted. By default, this
function is intended for quoting the path section of the URL. The
optional safe parameter specifies additional characters that should
not be quoted — its default value is '/'.
So, the reason is that it's escaping the path, and '/'
is a perfectly expected and valid character within a path.