Hello dear friends! Today we want to talk about how to create a new user on the Django website using Django Admin. This is one of the most practical features that can help you easily add new users to your projects.
Django Admin is a very powerful management tool that allows you to manage your data without needing excessive coding. This system automatically creates a management panel based on the models you define in Django. A main feature of this tool is the ability to add new users, which is very simple and efficient.
To use Django Admin to create a new user, there’s no need to write complex codes. In fact, this tool allows you to easily add users to the system with just a few clicks. This feature is especially beneficial for those who handle user management in a web system, as it significantly simplifies the process.
One of the interesting points about Django Admin is its simplicity and user-friendly interface. You can easily manage all your administrative operations through this interface. Additionally, you can customize the templates of this panel to better match the needs of your users.
Now let's see how we can add a new user using Django Admin. To do this, first, go to the management panel and navigate to the ‘Users’ section, then click the ‘Add User’ button. Then fill in the relevant fields such as username, password, and email address. In this way, your new user will be registered in the system.
<!--
Add a new user in Django Admin -->
from django.contrib.auth.models import User
# Create a new user
new_user = User.objects.create_user('newuser', '[email protected]', 'password123')
new_user.first_name = 'New'
new_user.last_name = 'User'
new_user.save()
Line 1: from django.contrib.auth.models import User
Importing the Django framework for working with user models.
Line 4: new_user = User.objects.create_user('newuser', '[email protected]', 'password123')
A new user is created with a username, email, and password specified.
Line 5: new_user.first_name = 'New'
Setting the first name of the new user.
Line 6: new_user.last_name = 'User'
Setting the last name of the new user.
Line 7: new_user.save()
Changes are saved in the database.