我尝试通过PUT将数据库中的对象更新到我的django后端。
我打电话的网址是PUT:
API_HOST + '/vehicles/V-123'
它像这样路由到我的更新方法:
from Tiresets.views import TiresetsSet
from Vehicles.views import VehiclesSet
from rest_framework_nested import routers
router = routers.SimpleRouter(trailing_slash=True)
router.register(r'vehicles', VehiclesSet, base_name='vehicles')
bundles_router = routers.NestedSimpleRouter(router, r'vehicles', lookup='vehicles')
bundles_router.register(r'tiresets', TiresetsSet, base_name='tiresets')
urlpatterns = router.urls + bundles_router.urls
它也正确跳转到我的Vehicles.views
的更新方法,但我无法从request.DATA
获取任何数据。我还确保数据已正确发送。
我的更新功能:
def update(self, request, pk=None):
data = request.DATA # <=== Here I don't get any data!!!
任何人都知道我在这里可能出错了什么?
答案 0 :(得分:1)
您可以尝试:
data = request.data
如下所述:
http://www.django-rest-framework.org/api-guide/requests/