V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Tornado Documentation
http://www.v2ex.com/tornado/
Tornado on GitHub
https://github.com/facebook/tornado/
Tornado Gists
http://tornadogists.org/
kenneth
V2EX  ›  Tornado

Jinja2的转义到底怎么用?

  •  
  •   kenneth · 2012-12-25 21:32:06 +08:00 · 8189 次点击
    这是一个创建于 4132 天前的主题,其中的信息可能已经有所发展或是发生改变。
    http://www.mvmap.com/t/1

    1.输入{% raw %}{{comment.content}}{% endraw %}
    输出{{comment.content}}
    2.直接{{comment.content}}
    直接显示转义的html


    到底错在哪里?
    16 条回复    1970-01-01 08:00:00 +08:00
    liubo
        1
    liubo  
       2012-12-25 21:40:51 +08:00
    试试{{comment.content|safe}}
    kenneth
        2
    kenneth  
    OP
       2012-12-25 21:42:32 +08:00
    @liubo 试过不行
    SErHo
        3
    SErHo  
       2012-12-25 22:13:43 +08:00
    囧,第一个是转义模板标签的,一楼是正确的。
    kenneth
        4
    kenneth  
    OP
       2012-12-25 22:19:35 +08:00
    @SErHo 哥们帮我看看http://www.mvmap.com/t/1下面的评论
    为什么html两边都有双引号,无法显示正确的链接。
    luztak
        5
    luztak  
       2012-12-25 22:43:09 +08:00
    @kenneth 估计是统一转了 要不 输出时转?
    这个 仅限于自己写的O o
    SErHo
        6
    SErHo  
       2012-12-25 22:48:31 +08:00
    @kenneth 你是不是写进数据库的时候就转了。
    kenneth
        7
    kenneth  
    OP
       2012-12-25 23:04:46 +08:00
    @luztak
    @SErHo
    我自己分析了半天,我觉得可能是我过滤器写的有问题。我还不知道错哪里,我先研究一下过滤器。
    henter
        8
    henter  
       2012-12-26 13:04:37 +08:00
    {{comment.content|raw}} ??
    kenneth
        9
    kenneth  
    OP
       2012-12-26 13:39:47 +08:00
    @henter TemplateAssertionError: no filter named 'raw'
    kenneth
        10
    kenneth  
    OP
       2012-12-26 21:20:38 +08:00
    @Livid 帮忙看一下错在哪里?
    yinian1992
        11
    yinian1992  
       2012-12-26 21:37:59 +08:00
    {% autoescape false %}
    自动转义在这块文本中是关闭的。
    {% endautoescape %}
    kenneth
        12
    kenneth  
    OP
       2012-12-27 08:15:36 +08:00   ❤️ 1
    @yinian1992
    TemplateSyntaxError: Encountered unknown tag 'autoescape'. Jinja was looking for the following tags: 'endfor' or 'else'. The innermost block that needs to be closed is 'for'.
    Catstyle
        13
    Catstyle  
       2012-12-27 09:25:19 +08:00
    @kenneth
    误击感谢...
    把上下文发出来看看
    0x0001
        14
    0x0001  
       2012-12-27 10:02:22 +08:00 via Android
    这样学习型的开发完全可放心地把代码都放到github上,不会写的不会部署你的代码,会写的还不如自己写。
    放出代码吧,这问题解决起来比你想象中简单。
    kenneth
        15
    kenneth  
    OP
       2012-12-27 10:36:52 +08:00
    @Catstyle 对误击感谢,表示感谢。
    @0x0001 不班门弄斧了,还是@Livid等官方的PB3吧,避免受我菜鸟思路误导。
    yinian1992
        16
    yinian1992  
       2012-12-27 15:34:13 +08:00
    @kenneth 需要 Jinja 版本 2.4 以上。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5459 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 03:12 · PVG 11:12 · LAX 20:12 · JFK 23:12
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.