我正在用烧瓶平板页构建博客。在减价blogpost的标题中,我按照文件名列出了相关的博客帖子。这些应显示为实际博客下面的摘录。在包含片段的模板中包含类似于视图的逻辑
这里是blogpost-1.md应该是这样的:
title: "Blogpost one"
published: 2014-02-13
related:
- blogpost-2.md
- blogpost-4.md
description: "This is the excerpt of blogpost one."
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer
vel leo turpis. Cras vulputate mattis dignissim. Aliquam eget
purus purus.
而结果我想:
BLOGPOST ONE
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer vel
leo turpis. Cras vulputate mattis dignissim. Aliquam eget purus purus.
related posts:
BLOGPOST TWO
Summary here
BLOGPOST THREE
Also a summary
的重要组成部分,是按照相关blogpostings的路径和渲染他们的头衔和除外。天真是这样的:
{% for item in blog.meta.related %}
<div>
<h4>{{ item.title }}</h4>
<p>{{ item.decription</p>
</div>
{% endfor %}
这显然是行不通的,因为meta.related
仅仅是一个字符串列表。这也不难作出这样的对待这些字符串并返回一个HttpResponse对象视图功能:
# app.py
@app.route('/excerpt/<path:path>.html')
def excerpt(path):
blog = blogs.get_or_404(path)
return render_template('excerpt.html', blog=blog)
# excerpt.html
<div>
<h4>{{ blog.meta.title }}</h4>
<p>{{ blog.meta.description }}</p>
</div>
我的问题:如何使这种情况发生在同一模板内?
我是否应该以某种方式尝试将相关博客的数据传递到上下文中:可能是一个dicts列表?我应该使用上下文处理器来实现吗?