A
A
awd102017-03-04 19:35:02
Django
awd10, 2017-03-04 19:35:02

How to connect recaptcha2 to django?

Installed the application https://github.com/kbytesys/django-recaptcha2
Set up on the docks. Added my form:

from recaptcha2.fields import ReCaptchaField
from recaptcha2.widgets import ReCaptchaWidget

class CaptchaForm(forms.Form):
    captcha = ReCaptchaField(
        widget=ReCaptchaWidget(),
        label='',
    )

When activated, it works on the client side. The problem starts when I want to do a check in views.py.
if request.POST:
            auth_form = AuthForm(request, request.POST)
            captcha_form = CaptchaForm(request, request.POST)
            username = request.POST.get('username')
            password = request.POST.get('password')
            user = auth.authenticate(username=username, password=password)
            #  if user is not None and auth_form.is_valid():
            if captcha_form.is_valid():
                auth.login(request, user)
                return HttpResponseRedirect('/')
            else:
                context['login_error'] = True
                return render(request, 'index.html', context)
        else:
            return render(request, 'index.html', context)

The form is still in test mode. Simple authorization works, but captcha_form.is_valid()gives an error:
AttributeError at /auth/
'WSGIRequest' object has no attribute 'get'

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
sim3x, 2017-03-04
@awd10

You don't need to do so

#
            username = request.POST.get('username')
            password = request.POST.get('password')

You need to use the built-in form functionality
https://docs.djangoproject.com/en/1.10/ref/forms/a...
You should also insert a captcha field in AuthForm
If docs.python-requests.org is used somewhere else then it needs to be ported in this way
And it has nothing to do with the Jungian request

D
devel787, 2017-03-06
@devel787

https://pythondigest.ru/feed/?q=recaptcha

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question