猿问

访问我的网站页面后无法登录管理页面

我在我的管理部分创建了一个超级用户。之后,我可以登录管理页面。但是每当我尝试访问一些 myapp 页面,然后我又想访问管理页面时,它会显示此错误“请为员工帐户输入正确的用户名和密码。请注意,这两个字段都可能区分大小写。” 我试过多次。我可以用上次创建的同名创建一个新的超级用户。这是两个屏幕截图:

http://img4.mukewang.com/6124c310000181eb06550398.jpg

如何解决这个问题?

温温酱
浏览 183回答 2
2回答

哆啦的时光机

我认为你把事情复杂化了。所以试试这样:# formsclass UserForm(forms.ModelForm):&nbsp; &nbsp; password = forms.CharField(widget= forms.PasswordInput)&nbsp; &nbsp; full_name = forms.CharField()&nbsp; &nbsp; codeforces_id = forms.CharField()&nbsp; &nbsp; Uva_Id = forms.CharField()&nbsp; &nbsp; class Meta:&nbsp; &nbsp; &nbsp; &nbsp; model = User&nbsp; &nbsp; &nbsp; &nbsp; fields = ('username','email','password', 'full_name', 'codeforces_id', 'Uva_Id')&nbsp;&nbsp; &nbsp; def save(self, commit=True):&nbsp; &nbsp; &nbsp; &nbsp; full_name = self.cleaned_data.pop('full_name')&nbsp; &nbsp; &nbsp; &nbsp; codeforces_id = self.cleaned_data.pop('codeforces_id')&nbsp; &nbsp; &nbsp; &nbsp; uva_Id = self.cleaned_data.pop('Uva_Id')&nbsp; &nbsp; &nbsp; &nbsp; user = super(UserForm, self).save(commit=False)&nbsp; &nbsp; &nbsp; &nbsp; password = self.cleaned_data.get('password')&nbsp; &nbsp; &nbsp; &nbsp; username = self.cleaned_data.get('username')&nbsp; &nbsp; &nbsp; &nbsp; user.set_password(password)&nbsp; &nbsp; &nbsp; &nbsp; user.save()&nbsp; &nbsp; &nbsp; &nbsp; Profile.objects.create(&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; user=user,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; full_name = full_name,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; codeforces_id = codeforces_id,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Uva_Id = uva_id&nbsp; &nbsp; &nbsp; &nbsp; )&nbsp; &nbsp; &nbsp; &nbsp; authenticate(username=username, password=password)&nbsp; &nbsp; &nbsp; &nbsp; return user# viewclass UserFormView(CreateView):&nbsp; &nbsp; form_class = UserForm&nbsp; &nbsp; template_name = 'some_template.html'# template<form action="/your-name/" method="post">&nbsp; &nbsp; {% csrf_token %}&nbsp; &nbsp; {{ form.as_p }}&nbsp; &nbsp; <input type="submit" value="Submit"></form># Also you can remove the signal related codes from Profile Model as well
随时随地看视频慕课网APP

相关分类

Python
我要回答