为什么我不能在get_context_data中调用带参数的方法?

时间:2014-04-17 22:53:22

标签: django

我不明白为什么我不能在get_context_data中调用带有参数的方法。通过删除参数它的工作原理。在发送到模板之前,更改基于类的视图上下文的推荐方法是什么?

class CustomerReportView(TemplateView):
    """Generate Customer Reports based on acct_id"""

    def whoami(self, username):
        """ 
        returns following information about the currently logged-in user 
        {'Name':'', 'Email':''}
        """
        records = {'Name':username, 'Email':'john.doe@email.com'}
        return records

    def get_context_data(self, **kwargs):
        context = super(CustomerReportView, self).get_context_data(**kwargs)
        context['now'] = self.whoami('john.doe@email.com')
        return context

0 个答案:

没有答案