V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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 · 2015-10-31 11:11:26 +08:00 · 1696 次点击
    这是一个创建于 3117 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

    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 %}

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5665 人在线   最高记录 6547   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 07:25 · PVG 15:25 · LAX 00:25 · JFK 03:25
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.