【发布时间】:2018-12-23 15:02:56
【问题描述】:
我正在尝试将我的 django 1.9 升级到 django 2.0。它对 GET() 工作正常,但在 POST() 中出现错误。
我的views.py 是:-
class AccountInfoUpdate(APIView):
authentication_classes = [IsAuthenticated]
def post(self, request):
user = request.user
user_profile = UserProfile.objects.get(user=user)
name = False
contact = False
if "name" in request.data:
user_profile.name = request.data.get('name')
user_profile.save()
name = True
if "contact" in request.data:
user_profile.contact = request.data.get('contact')
user_profile.save()
contact = True
if user_profile.affiliate_code is not None and (name or contact):
result = service.update_affiliate(user_profile.affiliate_code, name=user_profile.name,
contact=user_profile.contact)
return Response({'Message': 'Account info updated successfully!'})
我收到此错误:-
user_auth_tuple = authenticator.authenticate(self)
rest_framework.request.WrappedAttributeError: 'IsAuthenticated' object has no attribute 'authenticate'
如果我从 REST_FRAMEWORK 中删除或评论 'rest_framework.authentication.SessionAuthentication',,那么我会收到此错误 CSRF Failed: CSRF token missing or incorrect。
我尝试了permission_classes = [IsAuthenticated] 并在 Postman 上闲置,但仍然遇到同样的错误。
【问题讨论】:
标签: django django-rest-framework