Skip to content


Subversion checkout URL

You can clone with
Download ZIP


added urlencode filter, fix for issue #17 #62

wants to merge 1 commit into from

3 participants


No description provided.


Why do you call the filter urlencode if its actually urllib.quote, not urllib.urlencode?

because it was called this way in jinja-1


This is not unicode safe. If we would integrate such a filter we would have to select a default encoding. Not sure what to do there. Maybe force UTF-8 on everybody.

I also don't like the plus argument, because of that makes the choice whether to use the plus-variant or not up to the template author. But your application might require that all urls are quoted the same certain way.

In my opinion it would be appropriate to leave the implementation of that filter to the user, instead of providing a default implementation that either makes decisions (about the encoding and whether or not to use the plus-variant) for the user or requires them as argument, each time the filter is used.


The ... if ... else ... syntax isn't compatible with Python 2.4.


Duplicate, already implemented.

@mitsuhiko mitsuhiko closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 2, 2011
  1. @gfuchedzhy
This page is out of date. Refresh to see the latest.
Showing with 8 additions and 0 deletions.
  1. +8 −0 jinja2/
8 jinja2/
@@ -10,6 +10,7 @@
import re
import math
+from urllib import quote, quote_plus
from random import choice
from operator import itemgetter
from itertools import imap, groupby
@@ -394,6 +395,12 @@ def do_urlize(eval_ctx, value, trim_url_limit=None, nofollow=False):
rv = Markup(rv)
return rv
+def do_urlencode(value, plus=False):
+ """Return the urlencoded value. For detailed informations have a look at the
+ help page of "urllib.quote". If plus is set to True it will use the
+ "urllib.quote_plus" method.
+ """
+ return quote_plus(value) if plus else quote(value)
def do_indent(s, width=4, indentfirst=False):
"""Return a copy of the passed string, each line indented by
@@ -787,6 +794,7 @@ def do_attr(environment, obj, name):
'string': soft_unicode,
'list': do_list,
'urlize': do_urlize,
+ 'urlencode': do_urlencode,
'format': do_format,
'trim': do_trim,
'striptags': do_striptags,
Something went wrong with that request. Please try again.