我创建了MainUser模型,这个模型有 unicode 方法,但是这里我有像'unicode'对象不可调用的问题
这是我的授权功能:
def auth(request):
params = dict()
if request.method == 'POST':
try:
login = request.POST['login']
password = request.POST['password']
except:
messages.add_message(request, messages.WARNING, 'empty fields')
return redirect(reverse('main:sing_in'))
user = authenticate(username=login, password=password)
if user is not None:
login(request, user)
return redirect('main:work')
else:
return redirect(reverse('main:sing_in'))
return render(request, 'sing_in.html', params)
这是我的主用户模型:
class MainUser(AbstractBaseUser, PermissionsMixin):
"""
django user model
"""
login = models.CharField(max_length=20, blank=False, unique=True,
db_index=True, verbose_name=u'Логин')
first_name = models.CharField(max_length=222, blank=True,
verbose_name=u'Имя')
second_name = models.CharField(max_length=222, blank=True,
verbose_name=u'Фамилия')
email = models.EmailField(max_length=100, blank=True, verbose_name=u'email')
is_active = models.BooleanField(default=True)
is_admin = models.BooleanField(default=False)
objects = MainUserManager()
USERNAME_FIELD = 'login'
REQUIRED_FIELDS = []
def full(self):
return {
"first_name": self.first_name,
"second_name": self.second_name,
"email": self.email
}
@property
def is_staff(self):
return self.is_admin
def get_short_name(self):
return self.login
def get_full_name(self):
return u"{0} {1}".format(self.second_name, self.first_name)
def __unicode__(self):
return u"{}".format(self.login)
class Meta:
verbose_name = u"Пользователь"
verbose_name_plural = u"Пользователи"
我无法理解代码中的错误,当我调用login(request,user)时会出错。