Skip to content

Instantly share code, notes, and snippets.

@gcrsaldanha
Last active February 1, 2022 15:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gcrsaldanha/4d6d47db4620b4517678ba684b883333 to your computer and use it in GitHub Desktop.
Save gcrsaldanha/4d6d47db4620b4517678ba684b883333 to your computer and use it in GitHub Desktop.
Django Rest Framework playground
# https://www.django-rest-framework.org/api-guide/fields/#error_messages
from rest_framework import serializers as s
class User(s.Serializer):
name = s.CharField(error_messages={"blank": "This is a custom message! Yeah!"})
user = User(data={"name": ""})
user.is_valid()
print(user.errors)
@gcrsaldanha
Copy link
Author

In [9]: from rest_framework import serializers as s
   ...:
   ...:
   ...: class User(s.Serializer):
   ...:     name = s.CharField(error_messages={"blank": "This is a custom message! Yeah!"})
   ...:
   ...:
   ...: user = User(data={"name": ""})
   ...: user.is_valid()
   ...: print(user.errors)
{'name': [ErrorDetail(string='This is a custom message! Yeah!', code='blank')]}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment