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
Chyroc
V2EX  ›  Python

flask 模板有两个循环的数据怎么写

  •  
  •   Chyroc · 2016-08-29 18:29:02 +08:00 · 3726 次点击
    这是一个创建于 2796 天前的主题,其中的信息可能已经有所发展或是发生改变。

    有一个列表,大概是名称加内容的形式,如:

    名称:名称 1
    

    然后几行构成一个整体,比如:

    名称:名称 1
    时间:时间 1
    

    在一页里面有若干个以上这样的整体。

    我现在的数据有一个列表[名称, 时间, 作者]

    有一个数据 dict :

    [
    {
    'name':name1,
    'time':time1
    },
    {
    'name':name2,
    'time':time2
    }
    ]
    

    现在问怎么在模板里面写

    3 条回复    2016-08-30 10:08:36 +08:00
    zhuangzhuang1988
        1
    zhuangzhuang1988  
       2016-08-29 20:45:21 +08:00
    仔细仔细看 jinja2 文档。。
    NaVient
        2
    NaVient  
       2016-08-30 09:07:57 +08:00
    页面直接 for 循环就行了啊
    myyou
        3
    myyou  
       2016-08-30 10:08:36 +08:00
    ```
    {% for data in datas %}
    名称:{{data.name}}
    时间:{{data.time}}
    {% endfor %}
    ```
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1078 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 19:09 · PVG 03:09 · LAX 12:09 · JFK 15:09
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.