我正在尝试在 DRF(Django 版本 1.10)中集成基于令牌的身份验证,但是当我使用{"username":"test","password":"123456789"}
文档中提到的 api-token-auth/ 时,它需要返回我的令牌,但我得到了
{
"non_field_errors": [
"Unable to log in with provided credentials."
]
}
rest_framework.authtoken
一旦用户注册并保存在authtoken_token
table中,我已经在我安装的应用程序中使用了令牌。
同样在我正在使用的根目录的 urls.py 中
urlpatterns += [
url(r'^api-token-auth/', authviews.obtain_auth_token),
]
任何帮助,将不胜感激。还附上代码
urls.py
urlpatterns += [
url(r'^api-token-auth/', authviews.obtain_auth_token),
]
settings.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'rest_framework.authtoken',
'users'
]
users/urls.py
from rest_framework.routers import DefaultRouter
from . import views as user_views
from django.conf.urls import url ,include
router = DefaultRouter()
router.register(r'user', user_views.UserViewSet,base_name="user")
urlpatterns = router.urls