Django休息框架会话超时

时间:2016-07-27 06:06:27

标签: python angularjs django django-rest-framework django-sessions

在rest-api中,我使用了 django rest-framework 。我做过身份验证:
if username is not None and password is not None: user = authenticate(username=username, password=password) if user is not None: if user.is_active: token, created = Token.objects.get_or_create(user=user) if not created: token.created = datetime.datetime.utcnow().replace(tzinfo=utc) token.save() login(request, user) return Response({'token': token.key, 'username': user.username}) else: return Response({'status': status.HTTP_400_BAD_REQUEST}) else: return Response({'status': status.HTTP_400_BAD_REQUEST}) else: return Response({'status': status.HTTP_400_BAD_REQUEST})

注销:
token = Token.objects.get(key=request.data.get('token')) token.delete() logout(request) return Response({'status': status.HTTP_200_OK})

settings.py 中,权限类和身份验证类为:

`     ' DEFAULT_PERMISSION_CLASSES':[         ' rest_framework.permissions.IsAuthenticated&#39 ;,     ],

'DEFAULT_AUTHENTICATION_CLASSES': [
    'rest_framework.authentication.BasicAuthentication',
    'rest_framework.authentication.SessionAuthentication',
    'rest_framework.authentication.TokenAuthentication',
],`    

包含令牌的请求随附。我已经在angularjs中设置了10分钟的理想超时时间。

问题是在某个时间之后,即使它不理想,对于每个请求,休息框架都会响应身份验证问题。我猜,它是因为rest-framework的会话超时。

那么,任何人都可以提出解决此问题的路径,或者在 django rest-framework 中手动设置默认会话超时间隔吗?

提前致谢....

0 个答案:

没有答案