samgreeneggsham
samgreeneggsham

Reputation: 193

Pass parameter to form_class for RegistrationView

I'm trying to pass custom parameters to my form called 'RegistrationForm' using the RegistrationView class.

However when I do the following I just receive the error:

TypeError at /accounts/register/
'RegistrationForm' object is not callable

I'm guessing this is because I've created an object and I'm not just passing the class name to RegistrationView.

Is there any way I can achieve this?

urls.py

url(r'^register/$',
    RegistrationViewBillingSecret.as_view(template_name='registration/registration_form.html'),
    name='registration_register'),

views.py

from registration.backends.default.views import RegistrationView
class RegistrationViewBillingSecret(RegistrationView):
    form_class = RegistrationForm(billing_secret='somestring')

Upvotes: 1

Views: 1070

Answers (1)

samgreeneggsham
samgreeneggsham

Reputation: 193

I seem to have this ability to only figure out how to solve the problem after I've asked the question.

Here is what I did to accept parameters for my form_class and also my RegistrationView subclass.

class RegistrationViewBillingSecret(RegistrationView):
    form_class = RegistrationForm
    billing_secret = None
    def get_form_kwargs(self):
        kwargs = super(RegistrationViewBillingSecret, self).get_form_kwargs()
        kwargs.update({'billing_secret': self.billing_secret})
        return kwargs
    def __init__(self, *args, **kwargs):
        self.billing_secret = kwargs.pop('billing_secret', None)

Upvotes: 1

Related Questions