Django urldecode in template file

Is there a way urldecodein a Django template file?

Just opposite urlencode or escape

I want to convert app%20llctoapp llc

+5
source share
2 answers

You can create a simple custom filter around urllib.unquote

For instance:

from django.template.defaultfilters import stringfilter
from urllib import unquote

@stringfilter
def unquote_raw(value):
    return unquote(value)

and now you can get this in your django template file:

{{ raw|unquote_raw }}
+5
source

you need to write something like this instead of the previous answer, otherwise you will get the maximum recursion depth

from urllib import unquote

@register.filter
def unquote_new(value):
    return unquote(value)

{{raw | unquote_new}}

+4
source

All Articles