reset_admin_password.py 481 B

1234567891011121314
  1. from django.conf import settings
  2. from django.contrib.auth.models import User
  3. from django.core.management.base import BaseCommand, CommandError
  4. class Command(BaseCommand):
  5. def handle(self, **options):
  6. try:
  7. admin_user = User.objects.get(username="admin")
  8. except User.DoesNotExist:
  9. raise CommandError("Cannot find admin user.")
  10. admin_user.set_password(settings.ADMIN_PASSWORD)
  11. admin_user.save(update_fields=["password"])