开发者

Django urldecode in template file

开发者 https://www.devze.com 2023-02-15 16:31 出处:网络
is there any way do the urldecode in Django template file? Just opposite开发者_JAVA技巧 to urlencode or escape

is there any way do the urldecode in Django template file?

Just opposite开发者_JAVA技巧 to urlencode or escape

I want to convert app%20llc to app llc


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

from urllib import unquote
from django.template.defaultfilters import register
from urllib.parse import unquote #python3

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

{{ raw|unquote_new }}


You could 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 have this in your django template file:

{{ raw|unquote_raw }}
0

精彩评论

暂无评论...
验证码 换一张
取 消