注销无效

Ema*_*3sh 8 django django-rest-framework

我无法从其余api的浏览器模式注销当前用户.

这是我的设置

REST_FRAMEWORK = {
               'PAGINATE_BY': 10,  
                 'DEFAULT_AUTHENTICATION_CLASSES': (  
                      'rest_framework.authentication.BasicAuthentication',  
                      'rest_framework.authentication.SessionAuthentication',  
                      'rest_framework.authentication.TokenAuthentication',  
                                                 ),  
                  'DEFAULT_PERMISSION_CLASSES': (  
                      'rest_framework.permissions.IsAuthenticated',  
                                      ),  
                 }
Run Code Online (Sandbox Code Playgroud)

是因为我使用过会话吗?请帮忙.

请求和响应标头:

Request URL:`http://localhost:8000/api/api-auth/logout/?next=/api/city/`   
Request Method:GET  
Status Code:302 FOUND  
Request Headers:
---------------
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8  
Accept-Encoding:gzip,deflate,sdch  
Accept-Language:en-US,en;q=0.8  
Connection:keep-alive  
Cookie:sessionid=j7qebcdjdwzwqlmep4eyq3svuial43uv; csrftoken=vK3Ghn3QFVbCe3nKx1LDZBTzM7sRiDym  
Host:127.0.0.1:8000  
Referer:`http://localhost:8000/api/city/`
User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko)   Chrome/28.0.1500.71 Safari/537.36  
Query String Parametersview sourceview URL encoded  
next:/api/city/  
Response Headers  
----------------
Content-Type:text/html; charset=utf-8  
Date:Mon, 15 Jul 2013 20:46:35 GMT  
Location:`http://localhost:8000/api/city/`  
Server:WSGIServer/0.1 Python/2.7.4  
Set-Cookie:sessionid=b1x24z93dqu384lqirtv5r9npy16s0qx; expires=Mon, 29-Jul-2013 20:46:35 GMT;  httponly; Max-Age=1209600; Path=/
Vary:Cookie  
Run Code Online (Sandbox Code Playgroud)

Ema*_*3sh 18

解决了!这是因为启用了BasicAuthentication.我想我通过浏览器中的HTTP登录登录并注销似乎不适用于此.我删除了BasicAuthentication,现在一切似乎都正常.

  • 通过评论 BasicAuthentication,只要我使用泛型,它就运行良好,当我切换回 APIView 时,我仍然无法注销 (2认同)

小智 5

我今天遇到了这个问题,通过将顺序更改为以下内容解决了它:

'DEFAULT_AUTHENTICATION_CLASSES': (
    'rest_framework.authentication.SessionAuthentication',
    'rest_framework.authentication.BasicAuthentication',
    'rest_framework.authentication.TokenAuthentication',
),
Run Code Online (Sandbox Code Playgroud)