Python 在django的一个项目中,如何在一个模板中显示两个不同应用程序和不同视图的上下文?

Python 在django的一个项目中,如何在一个模板中显示两个不同应用程序和不同视图的上下文?,python,django,templates,jinja2,Python,Django,Templates,Jinja2,我有一个项目,它有不同的观点和不同的功能。 我想在其他html应用程序中访问和显示其中一个视图的上下文。 这是我的密码 垫圈.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

我有一个项目,它有不同的观点和不同的功能。 我想在其他html应用程序中访问和显示其中一个视图的上下文。 这是我的密码

垫圈.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)
垫圈.视图.py

  def home(request):
     template= "base.html"
     return render(request,template,context={})
如何访问产品列表视图的上下文并在base.html中显示它? 我可以在不同的应用程序中将一个html设置为两个不同的视图吗?以及两者的上下文访问? 我该怎么办?
tnx寻求帮助。

我不确定您在这里真正想要实现什么,但您可以简单地将
垫片.views.py重写为

def home(request):
     template= "base.html"
     context = {
         "product_list_view": Product.objects.all(),
         'best_post':Product.objects.order_by('timefield')[0:2]
     }
     return render(request,template,context={})

显然,您将需要从垫圈.垫圈.models导入产品添加

这是我的主要问题,当我想在该套件的其他应用程序中添加产品时,垫圈垫圈当我写入代码时,您确实写入了错误,我转到上一个目录:从垫圈.垫圈.models导入产品获取此错误:ModuleNotFoundError:没有名为“垫圈.垫圈”的模块i知道如果我导入模型产品,我可以解决我的问题。您是否将其包含在
已安装的应用程序中
?已安装的应用程序=['django.contrib.admin'、'django.contrib.auth'、'django.contrib.contenttypes'、'django.contrib.sessions'、'django.contrib.messages'、'django.contrib.staticfiles'、'comments'、'wash'、'newsletts'、'taggit'、]是的,我在遇到这个问题之前就做了,我想在基本页面上有最好的产品和时事通讯…但我无法将它们导入基本应用程序并使用它们。文件结构是什么?您的错误是“没有名为“垫片.垫圈”的模块”,但我不知道为什么
垫片
无法访问产品,所以我转到了垫圈目录,该目录是ga但现在我在这张照片上发现了这个错误: