I'm triying to add Recaptcha to my login form in Django. I tried different libraries but none of them seems to work, since the captcha form just doesn't appear in my template.
Here is my current work:
urls.py
path(r'captcha/', include('captcha.urls'))
forms.py
class NewUserForm(UserCreationForm):
email = forms.EmailField(required=True)
class YourForm(forms.Form):
captcha = CaptchaField()
class Meta:
model = User
fields = ("username", "email", "password1", "password2")
def save(self, commit=True):
user = super(NewUserForm, self).save(commit=False)
user.email = self.cleaned_data['email']
if commit:
user.save()
return user
And here is my login.html template
<form action="/your-name/" method="post">
{% csrf_token %}
{{ form.captcha }}
<input type="submit" value="Submit">
</form>
In this case, only the Submit
button will appear, but not the captcha
form. This is what happened with any other library I tried. Can anyone give me some help? Thanks in advance!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…