I'm using the Django rest-auth
package. I have a class that extends rest-auth
's RegisterView
, and which contains two methods, create
and perform_create
. What is the difference between these two methods?
Asked
Active
Viewed 1.4k times
19

GluePear
- 7,244
- 20
- 67
- 120
-
I think you got your answer – Anoop Kumar Nov 15 '18 at 12:21
-
Thanks. For more information you can see the tutorial on youtube https://www.youtube.com/watch?v=ekhUhignYTU&index=7&list=PL1WVjBsN-_NJ4urkLt7iVDocVu_ZQgVzF – Anoop Kumar Nov 15 '18 at 12:25
1 Answers
38
perform_create
is called within the create
method to call the serializer for creation once it's known the serialization is valid. Specifically, serializer.save()
Code from the source - when in doubt check it:
class CreateModelMixin(object):
"""
Create a model instance.
"""
def create(self, request, *args, **kwargs):
serializer = self.get_serializer(data=request.data)
serializer.is_valid(raise_exception=True)
self.perform_create(serializer)
headers = self.get_success_headers(serializer.data)
return Response(serializer.data, status=status.HTTP_201_CREATED, headers=headers)
def perform_create(self, serializer):
serializer.save()
def get_success_headers(self, data):
try:
return {'Location': str(data[api_settings.URL_FIELD_NAME])}
except (TypeError, KeyError):
return {}

Pythonista
- 11,377
- 2
- 31
- 50