forumku

forumku (https://www.forumku.com/)
-   Indonesia Membangun! (https://www.forumku.com/indonesia-membangun-/)
-   -   Which command is used to create a superuser in Django? (https://www.forumku.com/indonesia-membangun-/101065-command-create-superuser-django.html)

citay44929 16th July 2022 05:58 PM

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()



All times are GMT +7. The time now is 07:12 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
Search Engine Optimisation provided by DragonByte SEO v2.0.37 (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.