I'm new to django and trying to figure out how some of the form processing works.
For example, I have this field:
class ReCaptchaField(forms.Field):
def __init__(self, *args, **kwargs):
super(ReCaptchaField, self).__init__(widget=ReCaptchaWidget)
The widget renders some HTML (reCaptcha2 stuff).
I understand the concept of Field.clean, but the existing code is cleaning an array, and I haven't been able to work out where those values come from or what they are:
def clean(self, values):
super(ReCaptchaField, self).clean(values[1])
recaptcha_challenge_value = smart_unicode(values[0])
recaptcha_response_value = smart_unicode(values[1])
... code to do stuff with the values
How can I figure out what those incoming values are? The widget has a value_from_datadict, but I can't see where those values get populated either.
class ReCaptchaWidget(forms.Widget):
def render(self, name, value, attrs=None):
return mark_safe(force_unicode(captcha.displayhtml(settings.RECAPTCHA_PUB_KEY)))
def value_from_datadict(self, data, files, name):
return data.get('recaptcha_challenge_field', None), data.get('recaptcha_response_field', None)
For example, there are variables named recaptcha_challenge_field, but that string literal isn't used anywhere else. Seems like magic going on here... ;(
Thanks for any pointers.
Doug