Updating reCaptcha (widget) in django-based OSQA

40 views
Skip to first unread message

DougN

unread,
Apr 20, 2018, 10:40:30 AM4/20/18
to Django users
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

Jani Tiainen

unread,
Apr 20, 2018, 12:13:26 PM4/20/18
to django...@googlegroups.com
I recently used similar stuff and IIRC recaptcha2 doesn't use one of those fields anymore.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/2630b767-678b-4f29-879a-4c2d01a3e252%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Melvyn Sopacua

unread,
Apr 21, 2018, 2:53:47 PM4/21/18
to django...@googlegroups.com
On vrijdag 20 april 2018 16:17:05 CEST DougN wrote:

> Thanks for any pointers.

Same. Could you include the URL to the repository of the captcha
implementation you're using? I've looked at 2 now and neither of them have the
code you posted.

--
Melvyn Sopacua

Jani Tiainen

unread,
Apr 23, 2018, 6:53:23 AM4/23/18
to django...@googlegroups.com
Hi,

I've been using following implementation:
https://github.com/praekelt/django-recaptcha
Which has similar code.


Currently I'm actually using invisible ReCaptcha which works just fine with field.



--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

For more options, visit https://groups.google.com/d/optout.



--
Jani Tiainen

- Well planned is half done, and a half done has been sufficient before...

DougN

unread,
Apr 23, 2018, 12:15:35 PM4/23/18
to Django users
Hi Melvyn -

Same. Could you include the URL to the repository of the captcha
implementation you're using? I've looked at 2 now and neither of them have the
code you posted.

I did a little write up with a .zip file of the code at the end here:


I hope it's helpful.

Doug 
Reply all
Reply to author
Forward
0 new messages