点击收藏问题

来源:7-12 课程机构收藏功能

测试开发大牛

2018-03-12

老师,我点击收藏,日志报错。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')

和老师的代码一样,求解决

写回答

3回答

飞海

2018-04-01

请问你是如何解决的?

1
1
lemon333
ajax配置的页面失败跳转页面路径
2018-07-04
共1条回复

路上的小乌龟

2019-04-06

同样的问题请问怎么解决的?

0
0

测试开发大牛

提问者

2018-03-13

已解决

0
5
weixin_慕移动5185749
回复
路上的小乌龟
怎么解决的啊,@bobby
2019-05-26
共5条回复

Python3.6+django+xadmin,打造在线教育平台

【毕设】Python 2.7到3.6 完美适配,Django升级2.0

3677 学习 · 4041 问题

查看课程