Kai
Kai

Reputation: 2325

django-registration custom registration form (recaptcha field)

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('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.

Upvotes: 0

Views: 4383

Answers (3)

Marco Fucci
Marco Fucci

Reputation: 1854

'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.

Upvotes: -1

piyer
piyer

Reputation: 746

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

Upvotes: 0

John Debs
John Debs

Reputation: 3784

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.

Upvotes: 2

Related Questions