我正在尝试在我的表单上实现 Django reCAPTCHA。问题是,它不会每次都验证 reCAPTCHA 会话,我正确提交了表单。我尝试提交 reCAPTCHA 表单大约 30 次,但仍然无法验证 reCAPTCHA。
我已经在开发服务器上实现了 reCAPTCHA,并将域添加为 www.example.com 。
我也在使用本教程http://www.chrisumbel.com/article/recaptcha_with_django
这可能是为什么它无法验证的原因,因为我正在使用开发,否则有人可以帮助我吗?
from django.contrib.auth.views import password_reset
from django.shortcuts import render
from recaptcha.client import captcha
def forgot_password(request):
if request.method == 'POST':
response = captcha.submit(request.POST.get('recaptcha_challenge_field'), request.POST.get('recaptcha_response_field'), '1231d12dsad12', request.META['REMOTE_ADDR'],)
if response.is_valid:
captcha_response = "YOU ARE HUMAN: %(data)s" % {'data' : edit_form.data['data_field']}
else:
captcha_response = 'YOU ARE ROBOT'
return render(request, 'forgot_password.html',{'captcha_response':captcha_response})
else:
return render(request, 'forgot_password.html')
模板
{% block title %}Forgot Password<br>{% endblock title %}
<form method="post" action="{% url accounts:forgot-password %}">
{% csrf_token %}
<p>Please enter your email address.
You will receive a link to create a new password via email.</p>
<input type="email" name="email"
placeholder="Your e-mail"><br/>
<th>Are you human?</th>
<span class="validation_error">{{ captcha_response }}</span>
<script type="text/javascript"
src="http://api.recaptcha.net/challenge?k=123dwqsdasd123e23d32d32">
</script>
<noscript>
<iframe src="http://api.recaptcha.net/noscript?k=123dwqsdasd123e23d32d32">
height="300" width="500" frameborder="0"></iframe><br>
<textarea name="recaptcha_challenge_field" rows="3" cols="40">
</textarea>
<input type="hidden" name="recaptcha_response_field"
value="manual_challenge">
</noscript>
<button type="submit">Send new password</button>
</form>