Django Tutorial: Django Admin Interface Introduction

Опубликовано: 01 Октябрь 2024
на канале: Daily dose of America
1,685
8

In this Django tutorial, we will explore the Django Admin interface. One of the coolest features in the Django framework is the admin site. The admin interface allows for authorized users to manage content in the Django project.

The interface is only designed to be used by the administrators of a website. This feature should not be used by the users of a website. If you want to allow your users the ability to change content then I suggest building a backend for the users that is more secure from the admin interface which allows for sensitive information to be accessed. We will build a user interface separate from the admin interface in our tutorial series.

How To Create A Superuser In Django
Before we can actually access the admin section we need to create a superuser. A superuser is a user who has all the permission allowed in Django so you would not want to create one for an average user of your site. The superuser is controlled by the Django's authentication system. The authentication system handles user accounts, groups, and permissions on your website. We will explore authentication system more in the future.

To create a superuser open your terminal and enter the following command. You will be prompted to answer a few questions that will allow you to login into the admin interface.

(lpt) Thomass-MBP:lpt Tommy$ python manage.py createsuperuser
Username (leave blank to use 'tommy'): tommy
Email address: [email protected]
Password:
Password (again):
Superuser created successfully.
The python manage.py createsuperuser command runs the Django's authentication system which will ask a few questions. The questions asked Username, Email Address, Password, Password Again. If you received a Superuser created successfully then we can actually access the admin interface.

Access Django Admin Interface
To access the Django admin interface we need to run the development server. To run the development server run the following command in your terminal.

(lpt) Thomass-MBP:lpt Tommy$ python manage.py runserver
Performing system checks...

System check identified no issues (0 silenced).
July 15, 2016 - 19:10:25
Django version 1.9.7, using settings 'lpt.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
If you received no warnings go ahead and access the admin panel at http://127.0.0.1:8000/admin and fill in your credentials. Once logged in you can tour the admin interface. Notice that one app is already installed and ready to go in the interface. The authentication app is available to us. Notice there is not more going on in here till we add our app to the admin interface.

Conclusion
In this tutorial we created a superuser in our Django project and then we used those credentials to access the admin interface. If you have any questions about how to create a superuser or the admin interface leave a comment below.