Python 将数据/请求传递到多个html文件
有没有办法将数据传递到多个html文件Python 将数据/请求传递到多个html文件,python,html,django,forms,view,Python,Html,Django,Forms,View,有没有办法将数据传递到多个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('-u
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文件将具有指向另一个文件的扩展链接 您可能希望创建一个包含其他两个模板的新模板,而不是使一个模板扩展另一个模板: 学习日志/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)
查看:
{% 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)
函数只能返回一个值。您的第二个return语句没有运行,因为您的函数已经返回了一些内容。