无法获取request.user子字段

时间:2018-02-05 18:13:37

标签: python django authentication

我是Django / Python的新手,我无法检索user属性,例如first_name。我错过了什么?

class principal(LoginRequiredMixin, TemplateView):

template_name = 'appPortal/index.html'

def get_context_data(self, **kwargs):
    usuario = self.request.user
    context = super().get_context_data(**kwargs)
    print (usuario)  ### OK, returns the logged user
    print (usuario.first_name)  ### Don't work, returns nothing
    print (usuario.get_short_name()) ### Don't work too
### The code continues, but the last two print() don't work

谢谢,

1 个答案:

答案 0 :(得分:0)

确保您不允许将必填字段留空!