[英]Passing data/request to multiple html files
Is there a way to pass data to multiple html files? 有没有一种方法可以将数据传递到多个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)
I want the data to passed onto both html files, but only one is actually rendered/displayed. 我希望将数据传递到两个html文件中,但实际上仅渲染/显示一个。
The html file that is displayed will have an extends linking to the other one. 显示的html文件将具有指向另一个文件的扩展链接。
You may want to create a new template that includes the other two instead of making one extend the other: 您可能想创建一个包含其他两个模板的新模板,而不是一个扩展另一个模板:
learning_logs/index.html : learning_logs / index.html :
{% include 'learning_logs/entry.html' %}
{% include 'learning_logs/text.html' %}
view : 查看 :
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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.