Forms for user registration¶
Several form classes are provided with django-registration-redux, covering common cases for gathering account information and implementing common constraints for user registration. These forms were designed with django-registration-redux’s default backend in mind, but may also be useful in other situations.
- class registration.forms.RegistrationForm¶
A simple form for registering an account. Has the following fields, all of which are required:
usernameThe username to use for the new account. This is represented as a text input which validates that the username is unique, consists entirely of alphanumeric characters and underscores and is at most 30 characters in length.
emailThe email address to use for the new account. This is represented as a text input which accepts email addresses up to 75 characters in length.
password1The password to use for the new account. This represented as a password input (
input type="password"in the rendered HTML).password2The password to use for the new account. This represented as a password input (
input type="password"in the rendered HTML). Password mismatches are recorded as errors ofpassword2.
The constraints on usernames and email addresses match those enforced by Django’s default authentication backend for instances of
django.contrib.auth.models.User. The repeated entry of the password serves to catch typos.
- class registration.forms.RegistrationFormTermsOfService¶
A subclass of
RegistrationFormwhich adds one additional, required field:tosA checkbox indicating agreement to the site’s terms of service/user agreement.
- class registration.forms.RegistrationFormUniqueEmail¶
A subclass of
RegistrationFormwhich enforces uniqueness of email addresses in addition to uniqueness of usernames.
- class registration.forms.RegistrationFormNoFreeEmail¶
A subclass of
RegistrationFormwhich disallows registration using addresses from some common free email providers. This can, in some cases, cut down on automated registration by spambots.By default, the following domains are disallowed for email addresses:
aim.comaol.comemail.comgmail.comgooglemail.comhotmail.comhushmail.commsn.commail.rumailinator.comlive.comyahoo.comoutlook.com
To change this, subclass this form and set the class attribute
bad_domainsto a list of domains you wish to disallow.
Multiple Form Inheritance¶
Multiple RegistrationForm subclasses can be inherited into one class.
For instance, if your project requires a terms of service and a unique email
upon registration, those subclasses can be inherited into a single class. That
would look like this:
# myapp/forms.py
class CustomForm(RegistrationFormTermsOfService, RegistrationFormUniqueEmail):
pass
NOTE: If inheriting both RegistrationFormNoFreeEmail and
RegistrationFormUniqueEmail. RegistrationFormNoFreeEmail
must be inherited first, like this:
# myapp/forms.py
class CustomForm(RegistrationFormNoFreeEmail, RegistrationFormUniqueEmail):
pass
You can also add any customization to the form, to add additional fields for
example. Once you have built your form you must update the
REGISTRATION_FORM reflect the string dotted path to the form you wish
to use. For our example in settings.py you would change
REGISTRATION_FORM = 'myapp.forms.CustomForm'.