4

I use django-nocaptcha-recaptcha and followed the exact steps in the documantation: https://github.com/ImaginaryLandscape/django-nocaptcha-recaptcha

Here is my template:

{% extends 'base.html' %}

{% block content %}
<div class="col-sm6 col-sm-offset-3">
    <h1>HastePaste</h1>
    <form method="POST" action=""> {% csrf_token %}
        {{ form.as_p }}
        <input type="submit" class="btn btn-default">
        <div class="g-recaptcha" data-sitekey="6LfimBYTAAAAANXrMzDUVTiUHAm7ZaN2AR1Qs2SG"></div>
    </form>
</div>

{% endblock %}

with

<script src="https://www.google.com/recaptcha/api.js" async defer></script>

in the base.html.

My form:

from django import forms
from nocaptcha_recaptcha.fields import NoReCaptchaField
from posts.models import Post


class PostForm(forms.ModelForm):
class Meta:
    model = Post
    fields = '__all__'
    captcha = NoReCaptchaField()

The public key and the secret key are in the settings aswell as 'nocaptcha_recaptcha' in the installed apps. Any help would be great!

Edit: Sorry if my problem was not clear. Does not work means that the captcha shows up, but it has no effect. I can submit the form even if the captcha is unchecked.

Kaesekante
  • 109
  • 1
  • 9

1 Answers1

0

I solved the problem myself. The NoReCaptchaField should not be in the Meta class. It worked like this:

class PostForm(forms.ModelForm):
    class Meta:
        model = Post
        fields = '__all__'
    captcha = NoReCaptchaField()

No I get an error message if the captcha is ignored, but that is a different question I guess.

Kaesekante
  • 109
  • 1
  • 9