老师,我点击收藏,日志报错。int() argument must be a string, a bytes-like object or a number, not 'WSGIRequest'。代码如下:class AddFavView(View):
#用户收藏,已经用户取消收藏
def post(self, request):
fav_id = request.POST.get('fav_id', 0)
fav_type = request.POST.get('fav_type', 0)
if not request.user.is_authenticated():
#判断用户登录状态
return HttpResponse('{"status":"fail", "msg":"用户未登录"}', content_type='application/json')
exist_records = UserFavorite.objects.filter(user=request, fav_id=int(fav_id), fav_type=fav_type)
if exist_records:
#如果记录已经存在,则表示用户取消收藏
exist_records.delete()
return HttpResponse('{"status":"fail", "msg":"收藏"}', content_type='application/json')
else:
user_fav = UserFavorite()
if int(fav_id) > 0 and int(fav_type) > 0:
user_fav.fav_id = int(fav_id)
user_fav.fav_type = int(fav_type)
user_fav.save()
return HttpResponse('{"status":"success", "msg":"用户已收藏"}', content_type='application/json')
else:
return HttpResponse('{"status":"fail", "msg":"收藏出错"}', content_type='application/json')
和老师的代码一样,求解决