是否可以将数据传递到多个html文件?
def topic(request, topic_id):
topic = Topic.objects.get(id = topic_id)
entries = topic.entry_set.order_by('-date_added')
videos = topic.document_set.order_by('-upload_at')
images = topic.image_set.order_by('-upload_at')
context1 = {'topic': topic}
context2 = {'entries': entries}
return render(request, 'learning_logs/entry.html', context1)
return render(request, 'learning_logs/text.html', context2)
我希望将数据传递到两个html文件中,但实际上仅渲染/显示一个。
显示的html文件将具有链接到另一个的扩展。
答案 0 :(得分:0)
您可能想创建一个包含其他两个模板的新模板,而不是一个扩展另一个模板:
learning_logs / index.html :
{% include 'learning_logs/entry.html' %}
{% include 'learning_logs/text.html' %}
视图:
def topic(request, topic_id):
topic = Topic.objects.get(id = topic_id)
entries = topic.entry_set.order_by('-date_added')
videos = topic.document_set.order_by('-upload_at')
images = topic.image_set.order_by('-upload_at')
context = {
'topic': topic,
'entries': entries,
}
return render(request, 'learning_logs/index.html', context)