File tree 1 file changed +28
-0
lines changed
1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -152,3 +152,31 @@ Example usage ajax refresh
152
152
$('#id_captcha_0').val(result['key'])
153
153
});
154
154
});
155
+
156
+ Example usage in Django REST Framework
157
+ ---------------------------------
158
+
159
+ To use CAPTCHA in a serializer, simply inherit ``CaptchaSerializer ``::
160
+
161
+ from captcha.serializers import CaptchaSerializer
162
+ from rest_framework import serializers
163
+
164
+ class CheckCaptchaSerializer(CaptchaSerializer):
165
+ email = serializers.EmailField()
166
+
167
+ …or use ``CaptchaModelSerializer ``::
168
+
169
+ from captcha.serializers import CaptchaModelSerializer
170
+ from rest_framework import serializers
171
+
172
+ class CheckCaptchaModelSerializer(CaptchaModelSerializer):
173
+ sender = serializers.EmailField()
174
+
175
+ class Meta:
176
+ model = User
177
+ fields = ("captcha_code", "captcha_hashkey", "sender")
178
+
179
+ ``CaptchaSerializer `` and ``CaptchaModelSerializer `` implement the ``captcha_code `` and ``captcha_hashkey `` fields.
180
+ In case of invalid captcha or hash code an exception is raised::
181
+
182
+ raise exceptions.ValidationError({"error": gettext_lazy("Invalid CAPTCHA")})
You can’t perform that action at this time.
0 commit comments