Hello,
I am building my first Django Rest Framework project as a backend for mobile app and just today I implemented user registration via API. I couldn’t find any definitive tutorial related to registration so I pieced the code together using different SO answers and just wanna ask, whether this is a good approach.
class UsersSerializer(serializers.ModelSerializer):
class Meta:
model = core_models.CustomUser
fields = ('email', 'username', 'password')
def create(self, validated_data):
user = super(UsersSerializer, self).create(validated_data)
user.set_password(validated_data['password'])
user.save()
return user
And the view is just this:
class UserCreate(generics.CreateAPIView):
queryset = CustomUser.objects.all()
serializer_class = UsersSerializer
permission_classes = (AllowAny, )
Seems to be working fine when testing with Postman and then trying to log in. As a next step I want to enable Token authentification.
Thanks for help and suggestions!