【发布时间】:2014-04-04 02:19:09
【问题描述】:
有两个模型,需要同时在一个页面上显示它们。我知道我需要一个视图,其中包含两个模型。
哈哈
这是我得到的:
def inventory(request):
products = Product3.objects.all()
productinfo = {
"product_detail": products
}
return render_to_response('inventory.html', productinfo, context_instance=RequestContext(request))
def itemdetailpage(request, id):
property = Product3.objects.get(pk=id)
property1 = property.images.all()
itemin = {"itemdetail": property1 }
return render_to_response('details.html', itemin, context_instance=RequestContext(request))
如何将这些数据整合到一个视图中?所以我可以在一个模板中显示它们的两个内容,参数部分是 itemdetail 页面代码。?
视图中的解决方案如下: 我在发布这篇文章大约一个小时后发现了这一点,感谢 Dan 的回复,一切都完全正确:
def itemdetailpage(request, id):
property = Product3.objects.get(pk=id)
property1 = property.images.all()
itemin = {'property': property, 'imagedetail': property1}
return render_to_response('details.html', itemin, context_instance=RequestContext(request))
【问题讨论】:
标签: html django templates views models