Create superuser in Django

1. After building a project and open admin site

2. input this command in terminal

  
  
  
  
  1. $:manage.py shell 

3. Then input this in the python shell. This code will create a "admin" superuser

  
  
  
  
  1. >>> from django.contrib.auth.models import User 
  2. >>> user = User.objects.create_user('admin''[email protected]''12345'
  3. >>> user.is_superuser = True 
  4. >>> user.save() 

Ps. only superuser can edit "admin" site's content

4. If user need to change password or some attributes

  
  
  
  
  1. >>> from django.contrib.auth.models import User 
  2. >>> u = User.objects.get(username__exact='admin'
  3. >>> u.set_password('new password'
  4. >>> u.save() 

 

References: https://docs.djangoproject.com/en/1.4/topics/auth/#topics-auth-creating-superusers

 

 

你可能感兴趣的:(django,admin,djange)