View Single Post
Old 16th July 2022, 05:58 PM  
Warga Forumku
 
Join Date: 16 Jul 2022
Userid: 9567
Posts: 2
Likes: 0
Liked 0 Times in 0 Posts
Default Which command is used to create a superuser in Django?

Which command is used to create a superuser in Django?

If you're planning on publishing something on your server, you're going to want to create a superuser. This superuser has access to all your installed apps and can run management commands remotely. Here's how you do it with the Django command-line utility. The create user command is used to create a new user in Django.
Which command is used to create a superuser in Django? | CodeProZone
Code:
from django.core.management.base import BaseCommand, CommandError
from django.contrib.auth.models import User

class Command(BaseCommand):

    def handle(self, *args, **options):

        # The magic line
        User.objects.create_user(username= 'rmx',
                                email='superuser@super.com',
                                password='rmx55',
                                is_staff=True,
                                is_active=True,
                                is_superuser=True
        )
Code:
user@host> manage.py shell
>>> from django.contrib.auth.models import User
>>> user=User.objects.create_user('foo', password='bar')
>>> user.is_superuser=True
>>> user.is_staff=True
>>> user.save()
citay44929 is offline   Reply With Quote