0

I followed the django-recaptcha directions to add a field to my contact form. When it renders (in my local test), it has a field that says "Captcha:" but no actual captcha rendered. The dev console in chrome says

 Uncaught Error: Missing required parameters: sitekey

in https://www.gstatic.com/recaptcha/api2/v1531759913576/recaptcha__en.js

This answer says to add render=explicit to the javascript, but a) I'm not sure that's even the problem, b) I would think the Django package would handle it.

Django 1.11.8, Django recaptcha 1.4.0.

Django form is

class ContactForm(forms.Form):
    contacter = forms.EmailField(required=True,
                                 label=_('Your Email (optional)'),
                                 widget=forms.widgets.TextInput(
                                     attrs={'size': '50'}))
    contact_text = forms.CharField(required=True,
                                   widget=forms.widgets.Textarea(
                                       attrs={'rows': '10',
                                              'cols': '70',
                                              'class': 'defaultText',
                                              'title':
                                              _('Type a message here')}))
    captcha = ReCaptchaField()

The rendered Django form is below.

  <form action="/contact/"
        method="post" id="new-contact">
    <input type='hidden' name='csrfmiddlewaretoken' value='...' />

    <fieldset id="contact">
      <legend>Contact Us</legend>
      <tr><th><label for="id_contacter">Your Email (optional):</label></th><td><input type="text" name="contacter" required id="id_contacter" size="50" /></td></tr>
<tr><th><label for="id_contact_text">Contact text:</label></th><td><textarea name="contact_text" rows="10" title="Type a message here" id="id_contact_text" required cols="70" class="defaultText">
</textarea></td></tr>
<tr><th><label for="id_captcha">Captcha:</label></th><td><script src="https://www.google.com/recaptcha/api.js?hl=en"></script>
<div class="g-recaptcha" data-sitekey="" data-required="True" data-id="id_captcha" ></div>
<noscript>
  <div style="width: 302px; height: 352px;">
    <div style="width: 302px; height: 352px; position: relative;">
      <div style="width: 302px; height: 352px; position: absolute;">
        <iframe src="https://www.google.com/recaptcha/api/fallback?k="
                frameborder="0" scrolling="no"
                style="width: 302px; height:352px; border-style: none;">
        </iframe>
      </div>
      <div style="width: 250px; height: 80px; position: absolute; border-style: none;
                  bottom: 21px; left: 25px; margin: 0px; padding: 0px; right: 25px;">
        <textarea id="g-recaptcha-response" name="g-recaptcha-response"
                  class="recaptcha_challenge_field"
                  style="width: 250px; height: 80px; border: 1px solid #c1c1c1;
                         margin: 0px; padding: 0px; resize: none;" value="">
        </textarea>
        <input type="hidden" name="recaptcha_response_field" value="manual_challenge" />
      </div>
    </div>
  </div>
</noscript></td></tr>
    </fieldset>

    <input type="submit" value="Submit" />
  </form>
dfrankow
  • 20,191
  • 41
  • 152
  • 214

1 Answers1

0

I also filed this issue here.

Setting RECAPTCHA_PRIVATE_KEY and RECAPTCHA_PUBLIC_KEY to empty strings as directed produces this error. If instead those variables are completely unset (in the Django settings for the dev environment), the library uses the test keys, and all is well.

dfrankow
  • 20,191
  • 41
  • 152
  • 214