gpt4 book ai didi

django - 如何在 django View 中包含多个查询集?

转载 作者:行者123 更新时间:2023-12-03 09:13:16 24 4
gpt4 key购买 nike

是否可以在 View 函数中定义多个查询集?

最佳答案

这是示例

class MyMultiQuerysetView(TemplateView):
def get_context_data(self, **kwargs):
context_data = super().get_context_data(**kwargs)
context_data['queryset1'] = MyModel1.objects.all()
context_data['queryset2'] = MyModel2.objects.all()
return context_data

现在 queryset1queryset1 在您的模板中是可以接受的。

关于django - 如何在 django View 中包含多个查询集?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39883849/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com