Overview
Thereset_admin_password management command resets the password for the admin user to match the password defined in the ADMIN_PASSWORD setting. This is useful when deploying to different environments or when the admin password needs to be synchronized with environment configuration.
This command is automatically called by
reset_demo after reloading initial data to ensure the admin account is accessible.Usage
Command Arguments
This command does not accept any arguments or options.Configuration
The command reads the password from Django settings:The password to set for the admin user. This should be defined in your Django settings file or environment variables.
What It Does
The command performs a simple operation:Set Password
Updates the admin user’s password to match
settings.ADMIN_PASSWORD using Django’s secure password hashingExamples
Basic Usage
With Environment Variable
In Deployment Script
Source Code Location
bakerydemo/base/management/commands/reset_admin_password.py
Implementation
The command is straightforward:Error Handling
Admin User Not Found
If the admin user doesn’t exist in the database:load_initial_data command. Run that first:
Missing ADMIN_PASSWORD Setting
IfADMIN_PASSWORD is not defined in settings:
Security Considerations
Recommended Configuration
Development (.env.local)
Production (Environment Variables)
Settings Configuration
Use Cases
Environment Synchronization
When deploying to multiple environments (dev, staging, production), each can have its own admin password:Automated Testing
In CI/CD pipelines, set a known password for automated tests:Password Recovery
If you forget the admin password, reset it via the command:Integration with Other Commands
This command is automatically called by:reset_demo: After reloading data to ensure password matches environment
Admin User Details
The admin user created by initial data:- Username:
admin - Email: Defined in fixture data
- Permissions: Superuser with all permissions
- Password: Set via
ADMIN_PASSWORDsetting
Alternative Methods
Django changepassword Command
Django provides a built-in interactive command:Django Shell
Manually reset via Django shell:Wagtail Admin
Reset via the Wagtail admin interface (if you have access):- Login to
/admin/ - Go to Settings → Users
- Edit the admin user
- Set new password
Related Commands
reset_demo- Full demo reset (calls this command)load_initial_data- Loads admin user from fixtures
Best Practices
- Use Environment Variables: Store
ADMIN_PASSWORDin environment, not code - Different Passwords: Use different passwords per environment
- Strong Passwords: Generate random, strong passwords for production
- Document Access: Keep secure record of admin credentials
- Regular Rotation: Change admin password periodically
- Audit Access: Monitor admin login attempts

