推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
bradlee
V2EX  ›  Python

web新手 pytenjin的疑惑

  •  
  •   bradlee · Jun 2, 2013 · 4908 views
    This topic created in 4753 days ago, the information mentioned may be changed or developed.
    http://www.kuwata-lab.com/tenjin/pytenjin-users-guide.html
    这个地方是pytenjin的帮助文档,上面提到
    Template Syntax

    Notation:

    ${...} or {=...=}
    Python expression (with HTML escape)
    #{...} or {==...==}
    Python expression (without HTML escape)

    对于这两个模版方式,什么时候该用第一种,什么时候该用第二种?因为我看有的源码,实在是看不出这两种有什么区别?
    5 replies    1970-01-01 08:00:00 +08:00
    keakon
        1
    keakon  
       Jun 2, 2013   ❤️ 1
    ${'&'} 会输出 &
    #{'&'} 会输出 &

    除非你确定你要输出的就是 HTML,或者肯定不含特殊字符,那么使用后者。其他情况用前者。
    keakon
        2
    keakon  
       Jun 2, 2013
    呃,V2EX 把字符吞了,第一行是 & a m p ; (不含空格)
    bradlee
        3
    bradlee  
    OP
       Jun 2, 2013
    @keakon
    ${'&'} 会输出 &
    #{'&'} 会输出 & 看上去没区别啊,可以理解为第二种是第一种的子集关系?
    yetone
        4
    yetone  
       Jun 2, 2013 via Android   ❤️ 1
    @bradlee 简单点说,第一种可以防止 XSS
    bradlee
        5
    bradlee  
    OP
       Jun 2, 2013
    @yetone 谢谢 涨姿势了。。。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   856 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 123ms · UTC 19:56 · PVG 03:56 · LAX 12:56 · JFK 15:56
    ♥ Do have faith in what you're doing.