推荐学习书目
› 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
xiwangzishi
V2EX  ›  Python

Python 的模板引擎是如何工作的?

  •  
  •   xiwangzishi · May 14, 2014 · 4851 views
    This topic created in 4522 days ago, the information mentioned may be changed or developed.
    PHP 可以嵌套到 HTML 里,所以本身就可以看做是一种模板语言,那 Python 中像 Django、Jinja2 等这些模板引擎是如何工作的呢?
    6 replies  •  2014-05-15 00:16:22 +08:00
    summic
        1
    summic  
       May 14, 2014
    一切模板都是解析、替换、执行
    FarBox
        2
    FarBox  
       May 14, 2014
    编译成python能运行的脚本,并缓存。 请求模板的时候,将对应的变量传入,运行这个脚本。

    没有本质的区别。
    xiwangzishi
        3
    xiwangzishi  
    OP
       May 14, 2014
    @FarBox 谢谢,今天突然好奇这个。编译成python能运行的脚本,是通过解析模板字符串还是正则噢?感觉缺了点某些方面知识。
    FarBox
        4
    FarBox  
       May 14, 2014
    编译可能会有一些正则表达式,解析一般不会。

    这些东西其实不需要补,真要了解只能去看源码了。
    FarBox
        5
    FarBox  
       May 14, 2014
    @FarBox 抱歉,说错了。是渲染的时候,一般不会再用正则。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2391 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 43ms · UTC 15:29 · PVG 23:29 · LAX 08:29 · JFK 11:29
    ♥ Do have faith in what you're doing.