Jump to >


Common forms for authentication tasks.

These forms can be used either directly or as a base for more specific forms. They’re designed to take some of the complexity out of creating authentication-related forms not otherwise provided by Django.

class RegistrationForm(request=None, *args, **kwargs)[source]

Bases: django.forms.forms.Form

A standard registration form collecting basic account information.

This form prompts the user for a username, a password (and a confirmation on that password), e-mail address, first name, and last name. It then validates these, attempting to create a User.

This class can be extended by subclasses to provide additional fields.

__init__(request=None, *args, **kwargs)[source]

Initialize the form.

  • request (django.http.HttpRequest, optional) – The HTTP request from the client.
  • *args (tuple) – Positional arguments to pass to the parent class.
  • **kwargs (dict) – Keyword arguments to pass to the parent class.

Validate that the two supplied passwords match.

If they do not match, validation will fail, and an error will be supplied to the user.

Returns:The password supplied on the form.
Return type:unicode
Raises:django.core.exceptions.ValidationError – If the passwords do not match.

Save the form, creating a user if validation passes.

The user will be created with the provided username, e-mail address, password, and full name. If there are failures in creating this user, or there’s an existing user with the given name, an error will be raised. Creation always occurs in its own transaction, ensuring it’s immediately saved and preventing potential lookup problems when there’s a conflict.

Subclasses that want to override this can call the parent’s py:meth:save and modify the resulting user, if None is not returned.

Returns:The newly-created user, or None if there was a conflict when creating it.
Return type:django.contrib.auth.models.User
Raises:Exception – An unexpected exception occurred.
declared_fields = {'email': <django.forms.fields.EmailField object>, 'first_name': <django.forms.fields.CharField object>, 'last_name': <django.forms.fields.CharField object>, 'password1': <django.forms.fields.CharField object>, 'password2': <django.forms.fields.CharField object>, 'username': <django.forms.fields.RegexField object>}[source]