I'm trying to implement the google reCAPTCHA plugin into my form by following this tutorial http://blog.bixly.com/post/4069885657/how-to-add-recaptcha-to-your-django-forms
The steps look straight forward
Here are the steps to make it work:
1.Obtain a public and a private key.
2.Download a plugin for python.
3.Render the widget in the form page.
4.Verify the answer by sending a request to google’s server.
5.Check the response.
But when I get to step 3 in render the widget in the form page . I get this error. From reading the tutorial it doesn't refer me to import anything . Can someone help me
Rendering the widget The modules that you need from the plugin reside in recaptcha.client.captcha. It contains a method called displayhtml() that returns a string of javascript code which you use to render the widget. Here is a sample usage:
NameError at /account/forgot-password/
global name 'displayhtml' is not defined
Request Method: GET
Request URL: http://127.0.0.1:8000/account/forgot-password/
Django Version: 1.4.3
Exception Type: NameError
Exception Value:
global name 'displayhtml' is not defined
Traceback:
File "C:\Python26\lib\site-packages\django\core\handlers\base.py" in get_response
111. response = callback(request, *callback_args, **callback_kwargs)
File "C:\o\17\mysite\accounts\views.py" in forgot_password
12. script = displayhtml(public_key=public_key)
Exception Type: NameError at /account/forgot-password/
Exception Value: global name 'displayhtml' is not defined
Here are the steps to make it work:
Obtain a public and a private key.
Download a plugin for python.
Render the widget in the form page.
Verify the answer by sending a request to google’s server.
Check the response.
my views.py
from django.contrib.auth.views import password_reset
from django.shortcuts import render
from mysite.settings import *
def forgot_password(request):
if request.method == 'POST':
return password_reset(request,
from_email=request.POST.get('email'))
else:
public_key = 'DAAW231rf2ef23rfq'
script = displayhtml(public_key=public_key)
return render(request, 'forgot_password.html',{'script':script})
template
<form>
{{ form }}{% csrf_token %}
{{ script }}
</form>