使用 get_context_data Django 获取多个变量

Pick up multiple variables with get_context_data Django

我对 CBV Django 进程有疑问,get_context_data()

我想得到一些不同的变量,但我没有克服用我的函数来做它。

这是函数:

class IdentitySocietePDFCreatingView(LoginRequiredMixin, TemplateView) :

    template_name = 'Identity_Societe_PDF.html'
    model = Societe

    def get_context_data(self, **kwargs) :

        SID = Logger.login(lib.Global_variables.GED_LOG_USER, lib.Global_variables.GED_LOG_MDP)

        context_data = super(IdentitySocietePDFCreatingView, self).get_context_data(**kwargs)

        id = self.kwargs['id']
        societe = get_object_or_404(Societe, pk=id)

        obj = Societe.objects.filter (Nom=societe.Nom, SIRET=societe.SIRET, SIREN=societe.SIREN, Ville=societe.Ville)

        if obj:
            sc_obj = obj[0]

            ''' Rest of my script ''''
            ''' I have a variable named folderID which must be in my template ''''

        context_data['queryset'] = obj

        return context_data

我的问题是:

如何在 context_data 中添加 folderID 变量?我必须在我的模板中显示 objfolderID 但我没有克服在 context_data.

中添加这两个变量

context_data是一个dict,你可以添加任意多的东西给它。

context_data['folderID'] = 'foo'
context_data['obj'] = 'bar'