Eu estou usando o pacote django-simple-captcha
no meu aplicativo Django.
o documentação afirma que para adicionar o campo captcha em um formulário, tudo que você precisa fazer é
from django import forms
from captcha.fields import CaptchaField
class CaptchaTestForm(forms.Form):
myfield = AnyOtherField()
captcha = CaptchaField()
No entanto, como eu uso esse campo, se o meu formulário é uma forma crocante, que é a seguinte -
class SignupForm(authtoolsforms.UserCreationForm):
def __init__(self, *args, **kwargs):
super(SignupForm, self).__init__(*args, **kwargs)
self.helper = FormHelper()
self.fields["email"].widget.input_type = "email"
self.helper.layout = Layout(
Field("email", placeholder="Enter Email", autofocus=""),
Field("name", placeholder="Enter Full Name"),
Field("password1", placeholder="Enter Password"),
Field("password2", placeholder="Re-enter Password"),
Field("gender", placeholder="Gender"),
Submit("sign_up", "Sign up", css_class="btn-warning"),
)
Respostas:
1 para resposta № 1class SignupForm(authtoolsforms.UserCreationForm):
captcha = CaptchaField()
def __init__(self, *args, **kwargs):
super(SignupForm, self).__init__(*args, **kwargs)
self.helper = FormHelper()
self.fields["email"].widget.input_type = "email"
self.helper.layout = Layout(
Field("email", placeholder="Enter Email", autofocus=""),
Field("name", placeholder="Enter Full Name"),
Field("password1", placeholder="Enter Password"),
Field("password2", placeholder="Re-enter Password"),
Field("gender", placeholder="Gender"),
Field("captcha ", placeholder="Enter captcha"),
Submit("sign_up", "Sign up", css_class="btn-warning"),
)