2011-03-08 18 views

回答

5

你可以創建一個簡單的custom filter各地urllib.unquote

例如:

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

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

,現在你可以在你的django中有這個模板文件:

{{ raw|unquote_raw }} 
+0

我想要做的是模板文件不在視圖中 – 2011-03-08 06:24:21

+0

是你想要我做一些這樣的事情http://docs.djangoproject.com/en/dev/howto/custom-template-tags /? – 2011-03-08 06:26:09

+0

感謝它,但是這不引用'&'到'&' – 2011-03-08 06:48:29

4

你寫這樣的事情,而不是以前的答案,否則你會得到一個最大遞歸深度

from urllib import unquote 

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

{{原| unquote_new}}