views:

744

answers:

3

I try to add a recaptcha field to my registration form and followed Marcos guide:

http://www.marcofucci.com/tumblelog/26/jul/2009/integrating-recaptcha-with-django/

In my registration app, I have a file "forms.py" which looks like this:

from recaptcha import fields as captcha_field
from registration.forms import RegistrationFormUniqueEmail

class RecaptchaRegistrationForm(RegistrationFormUniqueEmail):
  recaptcha = captcha_field.ReCaptchaField()

and a urls.py which gets included under /accounts by my solution wide urls.py:

from django.conf.urls.defaults import *
from registration.views import register
from forms import RecaptchaRegistrationForm
urlpatterns = patterns('trackerbase.users.views',
                       (r'^$', 'profile'),
                       url(r'^register/$', register, {'form_class': RecaptchaRegistrationForm}, name='registration_register'),
                      )

Now, when I go to /accounts/register/ I get this error message:

Exception Value: register() takes at least 2 non-keyword arguments (1 given)

I have no idea why.

+2  A: 

The first non-keyword argument it's asking for is request, which is gets automatically.

The second non-keyword argument, which it isn't getting, is the authentication backend.

To get going quickly you can just use the default backend that comes with django-registration. I can't easily test this myself, but this should do it:

from django.conf.urls.defaults import *
from registration.views import register
from forms import RecaptchaRegistrationForm
from registration.backends.default import DefaultBackend
urlpatterns = patterns('trackerbase.users.views',
                       (r'^$', 'profile'),
                       url(r'^register/$', register, {
                       'backend': DefaultBackend,
                       'form_class': RecaptchaRegistrationForm,
                       }, name='registration_register'),
                       )

Take a look at the file you link to starting at line 95. Reading over that should tell you all you need to know.

John Debs
I tried that before, it doesn't work. I get this error:> Exception Value: type object 'DefaultBackend' has no attribute 'rfind'Because of that and because it says that backend is an optional argument, I thought that this just the wrong way of getting it to work and didn't mention it in my question.
Kai
Try 'backend': 'registration.backends.default.DefaultBackend'.
luc
A: 

You can use recaptcha-client, For step by step procedure you can follow k0001's blog it works out of the box.

Prashanth
A: 

'backend' isn't an optional argument. Can you please attach the stack trace of your exception? It seems like it's trying to use DefaultBackend as a string.

Marco Fucci
Traceback:File "/usr/lib/pymodules/python2.6/django/core/handlers/base.py" in get_response 92. response = callback(request, *callback_args, **callback_kwargs)File "/usr/local/lib/python2.6/dist-packages/registration/views.py" in register 178. backend = get_backend(backend)File "/usr/local/lib/python2.6/dist-packages/registration/backends/__init__.py" in get_backend 22. i = path.rfind('.')Exception Type: AttributeError at /accounts/register/Exception Value: type object 'DefaultBackend' has no attribute 'rfind'
Kai
Well, I tried: 'backend':'registration.backends.default.DefaultBackend' and there is no error message anymore, but at the same time, I get no recaptcha field either.
Kai
3 possibilities:1 - you haven't specified the 'form_class' argument (If not supplied, this will be retrieved from the registration backend.)2 - you are not displaying your form with {{ form }} (or {{ form_as_p }})3 - you have some problems with your recaptcha configuration. In this case, try creating your form using the python shell and print it. You should see an error if something is not properly configured.
Marco Fucci
Aah, i forgot to change the template. *grml* Thanks for pushing me there.
Kai