Hey there! This problem might be a bit unpredictable, but give it a go and let us know how you do!
How would you create a custom email validation for a User serializer in Django Rest Framework that only allows emails from the example.com domain?Serializers in DRF
Taming the email jungle at example.com
Report a typo
Reorder lines using drag or arrows. Adjust indentation with left buttons
fields = ['id', 'username', 'email']
from rest_framework import serializers
model = User
class Meta:
class UserSerializer(serializers.ModelSerializer):
return value
if not value.endswith('@example.com'):
raise serializers.ValidationError("Email must be from example.com domain")
def validate_email(self, value):
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.