推荐学习书目
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 · Aug 29, 2016 · 4248 views
    This topic created in 3627 days ago, the information mentioned may be changed or developed.

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

    名称:名称 1
    

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

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

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

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

    有一个数据 dict :

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

    现在问怎么在模板里面写

    3 replies    2016-08-30 10:08:36 +08:00
    zhuangzhuang1988
        1
    zhuangzhuang1988  
       Aug 29, 2016
    仔细仔细看 jinja2 文档。。
    NaVient
        2
    NaVient  
       Aug 30, 2016
    页面直接 for 循环就行了啊
    myyou
        3
    myyou  
       Aug 30, 2016
    ```
    {% for data in datas %}
    名称:{{data.name}}
    时间:{{data.time}}
    {% endfor %}
    ```
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3183 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 13:07 · PVG 21:07 · LAX 06:07 · JFK 09:07
    ♥ Do have faith in what you're doing.