Overview
Django-allauth is designed to work seamlessly with custom user models. This guide covers all configurations needed to use custom user models with different field names, email-only authentication, and username-less setups.Understanding Username vs Login Identifier
An important distinction in django-allauth:- USERNAME_FIELD (Django): The unique identifier field on your user model (e.g.,
email,user_id,uuid) - username (allauth): The field users type to log in (could be a nickname, handle, or login name)
email as your USERNAME_FIELD but not collect a separate username field at all.
Email-Only Authentication
The most common custom setup uses email as the primary identifier without usernames.User Model
models.py
Configuration
settings.py
Username and Email Authentication
Allow users to log in with either username or email.User Model
models.py
Configuration
settings.py
Custom Email Field Name
If your user model uses a different field name for email:models.py
settings.py
UUID as Primary Key
Using UUID instead of integer ID:models.py
settings.py
Custom Fields in Signup
Add additional fields to the signup process.User Model
models.py
Custom Signup Form
forms.py
Configuration
settings.py
Profile Model
Store additional user data in a separate profile model:models.py
forms.py
Adapter Customization
Customize user creation and validation:adapters.py
settings.py
Username Generation
If you need usernames but don’t want to collect them from users:adapters.py
Multiple User Types
Implement different user types (e.g., customers vs. vendors):models.py
forms.py
urls.py
Configuration Reference
ACCOUNT_USER_MODEL_USERNAME_FIELD
Default:"username"
The field on your user model that represents the login username. Set to None if you don’t have a username field.
ACCOUNT_USER_MODEL_EMAIL_FIELD
Default:"email"
The field on your user model that contains the email address. Set to None if you don’t have an email field.
ACCOUNT_USER_DISPLAY
Default: Returnsuser.username
Callable that returns the display name for a user.
Common Patterns
Email-Only (No Username)
settings.py
Username or Email Login
settings.py
Phone-Only Authentication
settings.py
Migration Guide
If you’re adding allauth to an existing project with a custom user model:-
Install allauth and add to
INSTALLED_APPS - Configure settings to match your user model:
settings.py
- Run migrations:
- Sync existing users with allauth’s EmailAddress model:
Best Practices
- Set user model early: Configure
AUTH_USER_MODELbefore first migration - Match allauth config: Ensure
ACCOUNT_USER_MODEL_*settings match your actual model - Validate early: Test signup/login flows immediately after configuration
- Use adapter methods: Override adapter methods rather than modifying allauth code
- Keep it simple: Start with standard fields, add complexity only when needed
