Base form classes¶
Several form classes are provided with django-registration, covering common cases for gathering account information and implementing common constraints for user registration. These forms were designed with django-registration’s built-in registration workflows in mind, but may also be useful in other situations.
A form for registering an account. This is a subclass of Django’s built-in
UserCreationForm, and has the following fields, all of which are required:
- The username to use for the new account.
- The email address to use for the new account.
- The password to use for the new account.
- The password to use for the new account, repeated to catch typos.
Validation of usernames
Django supplies a default regex-based validator for usernames in its base
AbstractBaseUserimplementation, allowing any word character along with the following set of additional characters: ., @, +, and -. However, in Django 1.11 on Python 2 this regex uses the
re.ASCIIflag, while on Python 3 it uses the
re.UNICODEflag. This means that if you’re using Django 1.11, the set of accepted characters will vary depending on the Python version you use.
Because it’s a subclass of Django’s
RegistrationFormwill inherit the base validation defined by Django. It also applies one custom validator:
ReservedNameValidator. See the documentation for
ReservedNameValidatorfor notes on why it exists and how to customize its behavior.
Unicode case handling
On all versions of Python, this form will normalize the username value to form NFKC, matching Django’s default approach to Unicode normalization. On Python 3, it will also case-fold the value (Python 3 provides a native
casefold()method on strings).
The validator will then use a case-insensitive (iexact) lookup to determine if a user with the same username already exists; the results of this query may depend on the quality of your database’s Unicode implementation, and on configuration details. The results may also be surprising to developers who are primarily used to English/ASCII text, as Unicode’s case rules can be quite complex.
A subclass of
RegistrationFormwhich adds one additional, required field:
- A checkbox indicating agreement to the site’s terms of service/user agreement.