Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use different form in Django-Registration

Django-Registration has several form classes in the forms.py file. One is "class RegistrationFormTermsOfService(RegistrationForm) ..

What do I change in the rest of Django Registration code to enable this form in my registration flow instead of RegistrationForm?

like image 433
Brenden Avatar asked Jun 20 '11 17:06

Brenden


2 Answers

Updating the accepted answer to conform with Django 1.5 and the latest version of django-registration:

in urls.py:

from registration.forms import RegistrationFormTermsOfService
from registration.backends.default.views import RegistrationView

urlpatterns = patterns('',
    url(r'^accounts/register/$', RegistrationView.as_view(form_class=RegistrationFormTermsOfService), name='registration_register'),
    # your other URLconf stuff follows ...
)

then update the registration_form.html template and add a tos field, e.g.:

<p>
<label for="id_tos">I accept the terms of service</label>
{% if form.tos.errors %}
    <p class="errors">{{ form.tos.errors.as_text }}</p>
{% endif %}
{{ form.tos }}
</p>
like image 173
Paolo Alexis Falcone Avatar answered Oct 05 '22 09:10

Paolo Alexis Falcone


You can simply go into your urls.py and override the form class by doing something like:

from registration.forms import RegistrationFormTermsOfService

(r'^accounts/register/$', 'registration.views.register', {'form_class' : RegistrationFormTermsOfService}),
like image 40
Abid A Avatar answered Oct 05 '22 09:10

Abid A