【发布时间】:2019-04-03 16:35:50
【问题描述】:
我有一个项目,上面有不同的视图和不同的功能。 我想在其他 html 应用程序中访问和显示其中一个视图的上下文。 这是我的代码
washer.views.py
def Product_list_view(request):
product_list_view = Product.objects.all()
best_post = Product.objects.order_by('timefield')[0:2]
context = {
"product_list_view": product_list_view,
'best_post':best_post
}
template_name = "product_list_view.html"
return render(request,template_name,context)
gasket.views.py
def home(request):
template= "base.html"
return render(request,template,context={})
如何访问 product_list_view 的上下文并将其显示在 base.html 中? 我可以在不同的应用程序中将一个 html 设置为两个不同的视图吗?并访问他们俩的上下文? 我必须做什么? tnx 帮助我。
【问题讨论】:
标签: python django templates jinja2