Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

How to create user from Django shell

  • Last Updated : 14 Sep, 2021

Let’s look at how to create a user for Django using Django’s interactive shell? Make sure you have the virtual environment activated, and you are within the folder that has the manage.py file. 

Note: Refer to the article How to Create a Basic Project using MVT in Django? to understand how to create a project in Django.

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course

Let’s launch Django’s interactive shell using the below command



python manage.py shell

You will get a similar output as mentioned below

Now enter the following code in the shell to create a user for Django.

Python3




from django.contrib.auth.models import User
  
user = User.objects.create_user('sonu','sonu@xyz.com','sn@pswrd')
user.save()

Let’s check our new user using superuser credentials. You can follow How to create superuser in Django? to create a superuser. Let’s start the server and log in using the admin URL (make sure path(‘admin/’, admin.site.urls), is mentioned in the URL patterns). 

http://127.0.0.1:8000/admin/

Sharing the screenshot below

You can check the newly added user details under the Users section. 

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!