django框架同时循环渲染多个列表

核心 zip函数
部分代码

    newFlows = Flow.objects.all()
    allArticle = []
    for flow in newFlows:
        article = Article.objects.get(article_id=flow.article_id)
        allArticle.append(article)
    articleAndFlow=zip(allArticle,flows)
    context = {
        'articleAndFlow':articleAndFlow
    }
    return render(request, 'flow.html', context)

渲染页面

   {% for article,flow in articleAndFlow %}
        

{{ article.title }} {{ flow.article_id }}

{% endfor %}

你可能感兴趣的:(python)