Django is a powerful web framework that allows developers to quickly create web applications. It is written in Python and is one of the most popular web frameworks available. One of the great features of Django is the built-in admin site. This admin site allows developers to quickly and easily manage their web applications. In this tutorial, we will show you how to use the Django admin site.
The first step is to install Django. This can be done using the pip package manager. To install Django, open a terminal window and run the following command:
pip install django
This will install the latest version of Django. Once the installation is complete, you can verify that it was successful by running the following command:
python -m django --version
This will print out the version of Django that was installed.
Once Django is installed, the next step is to create a project. A project is a collection of applications and settings that make up a web application. To create a project, open a terminal window and run the following command:
django-admin startproject myproject
This will create a directory called myproject. This directory will contain the settings and other files needed for the project. You can change the name of the directory if you wish.
The next step is to create an app. An app is a collection of code that performs a specific task. To create an app, open a terminal window and run the following command:
python manage.py startapp myapp
This will create a directory called myapp. This directory will contain the code for the app.
Once the app is created, it needs to be added to the project. To do this, open the settings.py file in the myproject directory and add the following line:
INSTALLED_APPS = [
'myapp',
]
This will add the app to the project.
The next step is to create a superuser. A superuser is a user with full access to the admin site. To create a superuser, open a terminal window and run the following command:
python manage.py createsuperuser
This will prompt you to enter a username, email address, and password. Once you have entered the information, the superuser will be created.
Once the superuser is created, the next step is to run the server. To do this, open a terminal window and run the following command:
python manage.py runserver
This will start the server and make it available on port 8000. You can access the server by going to http://localhost:8000 in your web browser.
Once the server is running, you can access the admin site by going to http://localhost:8000/admin in your web browser. This will open the admin site login page.
Once you are on the login page, you can log in using the superuser credentials that you created earlier. Once you are logged in, you will be taken to the admin site home page.
Once you are on the admin site home page, you can manage your site. You can add, edit, and delete models, view logs, and more. You can also access the Django documentation from the admin site.
In this tutorial, we have shown you how to use the Django admin site. We have covered how to install Django, create a project, create an app, add the app to the project, create a superuser, run the server, access the admin site, log in, and manage your site. We hope you have found this tutorial helpful.