aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework/mixins.py
diff options
context:
space:
mode:
Diffstat (limited to 'rest_framework/mixins.py')
-rw-r--r--rest_framework/mixins.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/rest_framework/mixins.py b/rest_framework/mixins.py
index 991f4c50..fbaaa96d 100644
--- a/rest_framework/mixins.py
+++ b/rest_framework/mixins.py
@@ -19,9 +19,16 @@ class CreateModelMixin(object):
if serializer.is_valid():
self.pre_save(serializer.object)
self.object = serializer.save()
- return Response(serializer.data, status=status.HTTP_201_CREATED)
+ headers = self.get_success_headers(serializer.data)
+ return Response(serializer.data, status=status.HTTP_201_CREATED, headers=headers)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
-
+
+ def get_success_headers(self, data):
+ if 'url' in data:
+ return {'Location': data.get('url')}
+ else:
+ return {}
+
def pre_save(self, obj):
pass