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

janja2 怎么使用 Extensions

  •  
  •   honmaple · Oct 31, 2015 · 2415 views
    This topic created in 3986 days ago, the information mentioned may be changed or developed.

    原谅我官方文档没看懂,官方文档就一句

    jinja_env = Environment(extensions=['jinja2.ext.i18n'])

    google 了一下,查到这个

    from jinja2 import Environment, FileSystemLoader
    loader = FileSystemLoader("templates")
    extensions = ['jinja2.ext.loopcontrols', 'jinja2.ext.autoescape', 'jinja2.ext.with_']
    env = Environment(extensions=extensions, loader=loader)
    template = env.get_template("index.html")
    return template.render(ID=ID)

    但结果还是不对,要么提示 index.html 找不到,要么就是 tag,break 的问题
    我只想在模板里使用

    {%- if loop.index >= 10 %}{% break %}{% endif %}

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1053 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 18:15 · PVG 02:15 · LAX 11:15 · JFK 14:15
    ♥ Do have faith in what you're doing.