如何通过Django中的人员状态过滤经过身份验证的用户?我遇到了麻烦

时间:2019-01-30 01:41:21

标签: django django-models

这里是我的所有密码,我还没有设置,只是常规身份验证

class login(View):
    template_name = "admin/page.html"
    context = {}
    def get(self, *args, **kwargs):
        next = self.request.GET.get('next')
        forms = adminForm()
        if next :
            self.context['next'] = next
        self.context['forms'] = forms
        return render(self.request, self.template_name, self.context)

    def post(self, *args, **kwargs):
        forms = adminForm(self.request.POST or None)
        next = self.request.POST.get('next')
        if forms.is_valid() :
            user = authenticate(username=forms.cleaned_data.get('username'), password=forms.cleaned_data.get('password'))
            login(self.request, user)# authenticate(username=forms.cleaned_data.get('username'), password=forms.cleaned_data.get('password')))
            if next :
                return redirect(next)
            return redirect('/admin/users')
        if not forms.is_valid() :
            self.context['errors'] = 'Invalid Username or Password'
        self.context['forms'] = forms
        return render(request, self.template_name, self.context)

0 个答案:

没有答案