当我对Tastypie API发出POST请求时出现以下错误:
{"error_message": "", "traceback": "Traceback (most recent call last):\n\n File \"/home/kelp/lib/python2.7/django_tastypie-0.9.11-py2.7.egg/tastypie/resources.py\", line 195, in wrapper\n response = callback(request, *args, **kwargs)\n\n File \"/home/kelp/lib/python2.7/django_tastypie-0.9.11-py2.7.egg/tastypie/resources.py\", line 407, in dispatch_list\n return self.dispatch('list', request, **kwargs)\n\n File \"/home/kelp/lib/python2.7/django_tastypie-0.9.11-py2.7.egg/tastypie/resources.py\", line 436, in dispatch\n response = method(request, **kwargs)\n\n File \"/home/kelp/lib/python2.7/django_tastypie-0.9.11-py2.7.egg/tastypie/resources.py\", line 1194, in post_list\n updated_bundle = self.obj_create(bundle, request=request, **self.remove_api_resource_names(kwargs))\n\n File \"/home/kelp/webapps/goals/goals/main/api.py\", line 191, in obj_create\n bundle = super(JoinedGoalResource, self).obj_create(bundle, request, user=request.user)\n\n File \"/home/kelp/lib/python2.7/django_tastypie-0.9.11-py2.7.egg/tastypie/resources.py\", line 1839, in obj_create\n bundle = self.full_hydrate(bundle)\n\n File \"/home/kelp/lib/python2.7/django_tastypie-0.9.11-py2.7.egg/tastypie/resources.py\", line 716, in full_hydrate\n value = field_object.hydrate(bundle)\n\n File \"/home/kelp/lib/python2.7/django_tastypie-0.9.11-py2.7.egg/tastypie/fields.py\", line 643, in hydrate\n value = super(ToOneField, self).hydrate(bundle)\n\n File \"/home/kelp/lib/python2.7/django_tastypie-0.9.11-py2.7.egg/tastypie/fields.py\", line 152, in hydrate\n elif self.attribute and getattr(bundle.obj, self.attribute, None):\n\n File \"/home/kelp/webapps/goals/lib/python2.7/django/db/models/fields/related.py\", line 301, in __get__\n raise self.field.rel.to.DoesNotExist\n\nDoesNotExist\n"}
我如何理解这个错误?
答案 0 :(得分:3)
了解django追溯的最佳方法是从底部开始向上移动,直到找到属于您的某些代码。一般来说django非常稳固,通常问题就是你正在做的事情:
File \“/ home / kelp / webapps / goals / goals / main / api.py \”,第191行,在 obj_create \ n bundle = super(JoinedGoalResource,self).obj_create(bundle, request,user = request.user)
您很可能正在传递对create的引用,并尝试解析对象上的外键关系。
我无法从您发布的内容中看到它,但您可以查看回溯中的最后一个条目,看看它正在查看的对象以及它所访问的不存在的关系。提示是它与您的包对象和坏字段有关。