我正在尝试使用 Django rest 框架和 react,redux 来实现用户注册表。我能够成功注册用户,但我在显示错误时遇到了问题,这些错误是由 Django 提供的,以防万一。
到目前为止我所做的
export const AUTH_START = 'AUTH_START';
export const AUTH_SUCCESS = 'AUTH_SUCCESS';
export const AUTH_FAIL = 'AUTH_FAIL';
export const AUTH_LOGOUT = 'AUTH_LOGOUT';
Run Code Online (Sandbox Code Playgroud)
这是Reducer功能
const initialState = {
token: null,
error: null,
loading: false
}
const authFail = (state, action) => {
return updateObject(state, {
error: action.error,
loading: false
});
}
const reducer = (state = initialState, action) => {
switch (action.type) {
case actionTypes.AUTH_START:
return authStart(state, action);
case actionTypes.AUTH_SUCCESS:
return authSuccess(state, action);
case …Run Code Online (Sandbox Code Playgroud) 我遇到了 DRF 登录按钮的问题。尽管登录、注册和注销功能按预期工作正常。但登录/注销按钮未显示。
到目前为止我做了什么
设置.py
INSTALLED_APPS = [
'rest_framework',
'knox',
]
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'knox.auth.TokenAuthentication',
'rest_framework.authentication.SessionAuthentication',
),
}
Run Code Online (Sandbox Code Playgroud)
urls.py
urlpatterns = [
path('api/auth', include('knox.urls')),
path('api/auth/register', RegisterAPI.as_view()),
path('api/auth/login', LoginAPI.as_view()),
path('api/auth/user', UserAPI.as_view()),
path('api/auth/logout', knox_views.LogoutView.as_view(), name='knox_logout')
]
Run Code Online (Sandbox Code Playgroud)