fork download
  1. from django.core.management.base import BaseCommand, CommandError
  2. from django.contrib.auth.models import User
  3.  
  4.  
  5. class Command(BaseCommand):
  6. help = 'Create a super user'
  7.  
  8. def handle(self, *args, **options):
  9. username = options['username']
  10. password = options['password']
  11.  
  12. u, created = User.objects.get_or_create(username=username)
  13. if created:
  14. u.is_superuser = True
  15. u.is_staff = True
  16. u.set_password(password)
  17. u.save()
  18. else:
  19. raise CommandError("user '%s' already exist" % username)
  20.  
  21. return "Password changed successfully for user '%s'" % u.username
  22.  
Runtime error #stdin #stdout #stderr 0.01s 7732KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "prog.py", line 1, in <module>
ImportError: No module named django.core.management.base