Acebiu
V2EX  ›  Flask

Flask 编写博客时 Pages 列表在首页显示怎么处理?

  •  
  •   Acebiu · Dec 4, 2015 · 2854 views
    This topic created in 3812 days ago, the information mentioned may be changed or developed.

    Flask 编写博客时 Pages 列表需要在首页显示。

    pages 是函数的返回值。

    base.html

    {% for page in pages %}
    <a href="">{{ page.title }}</a>
    {% endfor %}

    views.py

    各处类似以下
    @app.route('/')
    def index():
    return render_template('index.html', message='Hello Word')

    那么 base.html 这么就接收到 pages 呢?
    目前知道可以在 init.py 里面处理一下,然后在模板里面导入。
    还有别的解法吗?

    可能描述的不是特别清晰,望包涵。

    2 replies    2015-12-04 23:18:24 +08:00
    casparchen
        1
    casparchen  
       Dec 4, 2015 via iPhone
    你要传给 render 函数啊
    loading
        2
    loading  
       Dec 4, 2015 via Android
    连官方 demo 都没看完就敢提问!
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3610 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 10:39 · PVG 18:39 · LAX 03:39 · JFK 06:39
    ♥ Do have faith in what you're doing.