第一次使用在 tornado 里面写 coffeescript 的时候, 我被结果惊呆了.

大家知道 coffeescript 的偷懒写法是直接在 html 里面开工


但是, tornado 的模版无情的删除了所有缩进(对于html和js文件来说, 这就是压缩)

打开tornado的template.py一看

def __init__(self, template_string, name=\"\", loader=None,
             compress_whitespace=None, autoescape=_UNSET):
    self.name = name
    if compress_whitespace is None:
        compress_whitespace = name.endswith(\".html\") or \\
            name.endswith(\".js\")

如果是 .html 和 .js 结尾的模版文件渲染, 就会默认开启 compress_whitespace.

当时很沮丧…

不过下一秒钟我们就想到了解决方法: 把文件名改为 .htm 不就好了