Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django urldecode in template file

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

Just opposite to urlencode or escape

I want to convert app%20llc to app llc

like image 858
Mithun Sreedharan Avatar asked Mar 08 '11 06:03

Mithun Sreedharan


People also ask

Can I call a function in a Django template?

You cannot call a function that requires arguments in a template. Write a template tag or filter instead.

What does {% %} mean in Django?

{% %} and {{ }} are part of Django templating language. They are used to pass the variables from views to template. {% %} is basically used when you have an expression and are called tags while {{ }} is used to simply access the variable.

How do I use an inheritance template in Django?

extends tag is used for inheritance of templates in django. One needs to repeat the same code again and again. Using extends we can inherit templates as well as variables.

What is Forloop counter in Django?

A for loop is used for iterating over a sequence, like looping over items in an array, a list, or a dictionary.


2 Answers

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 }}

like image 134
psychok7 Avatar answered Oct 17 '22 05:10

psychok7


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 }}
like image 41
Rafael Ferreira Avatar answered Oct 17 '22 07:10

Rafael Ferreira