V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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 · 2087 views
    This topic created in 3839 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   ·   Solana   ·   993 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 23:18 · PVG 07:18 · LAX 16:18 · JFK 19:18
    ♥ Do have faith in what you're doing.