citay44929
16th July 2022, 05:58 PM
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 (https://codeprozone.com/code/python/149802/django-admin-create-superuser.html)
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
)
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()
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 (https://codeprozone.com/code/python/149802/django-admin-create-superuser.html)
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
)
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()