推荐学习书目
› 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 · 5010 views
    This topic created in 4572 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
    summic
    May 14, 2014
    1
    一切模板都是解析、替换、执行
    FarBox
    FarBox
    May 14, 2014
    2
    编译成python能运行的脚本,并缓存。 请求模板的时候,将对应的变量传入,运行这个脚本。

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

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