feed_obj = self.get_feed_obj(request, kwargs.get('feed_id'))
ad_ingredient_id = kwargs.get('ad_ingredient_id')
adingredient_obj = AdIngredient.objects.filter(feed_id=feed_obj.id, created_by_id=request.user.id, state=1).first()
for data in self.data_formating(request, feed_obj):
serializer = self.serializer_class(adingredient_obj,data=data,partial=True)
if serializer.is_valid():
serializer.save()
else:
return Response(
{
'success': False,
'detail': serializer.errors
},
status=status.HTTP_400_BAD_REQUEST
)
return Response(
{
'success': True,
'detail': 'Feed Ad Ingredients information updated successfully',
'data': feed_obj.id
},
status=status.HTTP_200_OK
)
它不是更新数据,它始终保留创建对象时添加的旧数据。
/ api / feeds / ad-ingredient / 55 /下的AttributeError “列表”对象没有属性“复制”
跟踪:
内部文件“ /Users/omairbukhari/env_justads/lib/python2.7/site-packages/django/core/handlers/exception.py” 39. response = get_response(request)
_legacy_get_response中的文件“ /Users/omairbukhari/env_justads/lib/python2.7/site-packages/django/core/handlers/base.py” 249. response = self._get_response(request)
_get_response中的文件“ /Users/omairbukhari/env_justads/lib/python2.7/site-packages/django/core/handlers/base.py” 187. response = self.process_exception_by_middleware(e,request)
_get_response中的文件“ /Users/omairbukhari/env_justads/lib/python2.7/site-packages/django/core/handlers/base.py” 185. response = wrapd_callback(request,* callback_args,** callback_kwargs)
wrapped_view中的文件“ /Users/omairbukhari/env_justads/lib/python2.7/site-packages/django/views/decorators/csrf.py” 58. return view_func(* args,** kwargs)
视图中的文件“ /Users/omairbukhari/env_justads/lib/python2.7/site-packages/rest_framework/viewsets.py” 83. return self.dispatch(request,* args,** kwargs)
文件“ /Users/omairbukhari/env_justads/lib/python2.7/site-packages/rest_framework/views.py”在分发中 477. response = self.handle_exception(exc)
handle_exception中的文件“ /Users/omairbukhari/env_justads/lib/python2.7/site-packages/rest_framework/views.py” 437. self.raise_uncaught_exception(exc)
文件“ /Users/omairbukhari/env_justads/lib/python2.7/site-packages/rest_framework/views.py”在分发中 474. response = handler(request,* args,** kwargs)
文件“ /Users/omairbukhari/justads/backend/feeds/views.py”已更新 738. request_data = request.data.copy()
答案 0 :(得分:0)
list.copy
是在Python 3.3中引入的。
您正在使用Python 2.7,因此应将正在使用的django的版本降级(至1.11
):
Django version Python versions
1.11 2.7, 3.4, 3.5, 3.6
2.0 3.4, 3.5, 3.6, 3.7
2.1, 2.2 3.5, 3.6, 3.7
更新
查看堆栈跟踪的最后一行:
File "/Users/omairbukhari/justads/backend/feeds/views.py" in update 738.
request_data = request.data.copy()
请使用空切片:request_data = request.data[:]
如果这不是您的代码不是,则说明您未正确降级django的版本。