我有一个自定义的用户模型为如下account/models.py
from django.contrib.auth.modles import AbstractUser
from django.db.models.signals import post_save
from rest_framework.authtoken.models import Token
from django.db import models
from django.dispatch import receiver
from django.conf import settings
@receiver(post_save, sender=settings.AUTH_USER_MODEL)
def create_auth_token(sender, instance=None, created=False, **kwargs):
if created:
Token.objects.create(user=instance)
class UserProfile(AbstractUser):
gender = models.CharField(max_length=1,default='')
在settings.py
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.TokenAuthentication',
)
}
...
AUTH_USER_MODEL = "account.UserProfile"
然而,每当我试图登录到浏览的API,它要求我使用正确的用户名和密码,我使用谁都是标记为超级用户和员工用户的凭据。
该manage.py runserver
控制台显示这条消息:
[27/Jul/2016 20:41:39] "POST /api-auth/login/ HTTP/1.1" 200 2897