这里是我的所有密码,我还没有设置,只是常规身份验证
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)