Reusable Django + DRF authentication starter boilerplate with:
- Custom
Usermodel (PermissionsMixin) with email + username login support - Web auth (register, login, logout, profile, password reset/change)
- Email verification + resend activation flow
- DRF auth APIs with
djangorestframework-simplejwt - SQLite default, PostgreSQL-ready via
DATABASE_URL - Clean project layout (
core/,apps/,base/)
See structure.md for the full tree.
Key modules:
core/- project config, settings, middleware, root URLs/templatesapps/accounts/- auth domain (models, forms, web views, API, email, tests)apps/home/- home appbase/- reusable base utilities
- Python 3.12+
- Virtual environment recommended
Install dependencies:
pip install -r requirements.txtCreate local env from example:
cp .env.example .envImportant variables:
DEBUG(default:True)SECRET_KEYALLOWED_HOSTSDATABASE_URL(default fallback: SQLitedb.sqlite3)APP_BASE_URL(used for email activation links)EMAIL_*settings
python manage.py migrate
python manage.py createsuperuser
python manage.py runserverSet DATABASE_URL in .env:
DATABASE_URL=postgres://postgres:postgres@127.0.0.1:5432/jtroauthThen run:
python manage.py migrate
python manage.py runserverIf PostgreSQL is not running, keep SQLite fallback by leaving DATABASE_URL unset or set to SQLite.
Login accepts either email or username (same password) for:
- Web login (
/accounts/login/) - Django admin (
/admin/login/) - API token endpoints (
/api/auth/login/,/api/auth/token/)
login/logout/register/activate/<uidb64>/<token>/email/resend/profile/profile/edit/password/change/password/reset/and confirm/complete routes
POST register/POST login/POST token/POST token/refresh/POST logout/GET me/POST password/reset/POST password/reset/confirm/POST email/verify/POST email/resend/
Token/login request example:
{
"identifier": "mohin_or_email@example.com",
"password": "your-password"
}email and username keys are still accepted for backward compatibility.
- User registers (
is_active=False,email_verified=False) - Username is optional on registration; if omitted it is auto-generated from the email local part
- policy: lowercase, non-alphanumeric characters converted to
_, uniqueness enforced with numeric suffixes
- policy: lowercase, non-alphanumeric characters converted to
- Activation email is sent with signed token link
- User verifies email via link or API verify endpoint
- Account becomes active and can obtain JWT tokens
Local default:
EMAIL_BACKEND=django.core.mail.backends.console.EmailBackend
SMTP example:
EMAIL_BACKEND=django.core.mail.backends.smtp.EmailBackend
EMAIL_HOST=smtp.example.com
EMAIL_PORT=587
EMAIL_HOST_USER=your-user
EMAIL_HOST_PASSWORD=your-password
EMAIL_USE_TLS=True
DEFAULT_FROM_EMAIL=no-reply@example.comEmail templates included:
- Account activation (HTML + text)
- Password reset (HTML + text + subject)
- Welcome email (optional)
Run:
python manage.py check
python manage.py makemigrations --check
python manage.py migrate
python manage.py test- Use
core.settings.production - Set a strong
SECRET_KEY - Set explicit
ALLOWED_HOSTS - Use SMTP/backend suitable for production
- Run behind a proper WSGI/ASGI server (not Django dev server)
- Removed legacy
djangorestframework-jwtusage - Migrated auth APIs to
djangorestframework-simplejwt - Moved legacy
src/customuserauthlayout to rootcore/apps/base - Added
.env.exampleandDATABASE_URLsupport - Rebuilt tests for models, web auth, and API auth flows