Ich benutze das Paket django-simple-captcha
in meiner Django App.
Das Dokumentation gibt an, dass alles, was Sie tun müssen, um das Captcha-Feld in einem Formular hinzuzufügen, ist
from django import forms
from captcha.fields import CaptchaField
class CaptchaTestForm(forms.Form):
myfield = AnyOtherField()
captcha = CaptchaField()
Wie verwende ich ein solches Feld, wenn es sich bei meiner Form um eine knusprige Form handelt?
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"),
)
Antworten:
1 für die Antwort № 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"),
)