【发布时间】:2019-05-29 00:39:12
【问题描述】:
您好,我正在使用 django rest-framework,我想实现基于令牌的身份验证, 我正在使用基本的 rest-framework 令牌认证模块。
但它在每个请求上都返回相同的令牌。 ex(87d97bb2df56e39c12b38131087bcfd232720d9a),我在向我的服务器发送的每个请求中都会收到此字符串。
我的 setting.py 文件
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'restApp2', # Local Apps (My project's apps)
'rest_framework',
'rest_framework.authtoken',
'rest_auth',
]
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework.authentication.TokenAuthentication', # <-- And here
],
}
urls.py 文件
from django.contrib import admin
from django.urls import path, include
from restApp2 import views
from rest_framework.authtoken.views import obtain_auth_token
urlpatterns = [
path('admin/', admin.site.urls),
path('hello/', views.HelloView.as_view(), name='hello'),
path('api-token-auth/', obtain_auth_token, name='api_token_auth'), # <-- And here
]
urlpatterns += [
path('accounts/', include('django.contrib.auth.urls')),
]
我正在使用 POSTMON 的 post 方法调用下面的 url。
POST http://localhost:7070/rest-auth/login/
作为回应,我得到了
87d97bb2df56e39c12b38131087bcfd232720d9a.
但我想要新请求时使用不同的令牌。
请帮帮我,谢谢
【问题讨论】:
标签: django python-3.x django-rest-framework django-rest-auth