reactjs - 对 django logout 的 api 调用未将用户注销
问题描述
我是 Django 新手,正在尝试实现登录/注销功能。我使用 React 作为我的前端。即使在向 /auth/logout/ 发出 Axios 请求后,我仍然可以看到用户在我的后端登录。它没有给出任何错误。 在这里我可以看到用户
这些是其余的框架设置
REST_FRAMEWORK = {
'DEFAULT_PARSER_CLASSES': [
'rest_framework.parsers.JSONParser',
],
'DEFAULT_PERMISSION_CLASSES': [
'rest_framework.permissions.AllowAny',
],
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework.authentication.SessionAuthentication',
]
}
网址.py
urlpatterns = [
url(r'^', include(router.urls)),
url(r'^auth/', include('rest_auth.urls')),
url(r'users/', UserListView.as_view(), name='userListView'),
]
注销视图.js
class LogoutView extends React.Component{
componentDidMount (){
Axios.post("http://127.0.0.1:8000/myaccount/auth/logout/", {withCredentials: true})
.then(response => {
console.log(response)
})
}
render(){
return(
<Logout />
)
}
}
这是我在注销调用后得到的响应对象
Object
config: {url: "http://127.0.0.1:8000/myaccount/auth/logout/", method: "post", data: "{"withCredentials":true}", headers: {…}, transformRequest: Array(1), …}
data: {detail: "Successfully logged out."}
headers: {content-length: "37", content-type: "application/json"}
request: XMLHttpRequest {readyState: 4, timeout: 0, withCredentials: false, upload: XMLHttpRequestUpload, onreadystatechange: ƒ, …}
status: 200
statusText: "OK"
解决方案
推荐阅读
- c++ - 将文件读入 C++ 一个“数组”对象(不是数组)
- c# - C# Entity Framework - 为什么使用匿名类型而不是类对象时查询要快得多?
- python-3.x - python中3d绘图中的线条
- javascript - 如何在 HTML 中更改页面的背景颜色?
- python - 处理数据框中的列表时的好习惯?
- qt - 如果函数 raise()、activeWindow() 和其他函数不起作用,我如何将 QFileDialog 提升到前台?
- r - 在子图的每个图上放置几个散点图
- java - web应用程序中的java.lang.UnsatisfiedLinkError chilkat java库错误
- sql - PostgreSQL - 在字符/字符串列中找到匹配行?
- sql - 使用 PIVOT 显示所有 varchar 值