How to Set up Admin Adminstration in Django 


               


How to Set up Admin Adminstration in Django



Python


In this article, we show how to set up admin administration in Django.

By setting up admin administration in Django, we can have administrative privileges to the website. This is useful for all types of things, including being able to monitor, delete blogs, users, etc.

So, to set up an admin for a website, open up your computer's command prompt and specify the full path to the project (website) that you created.

So, if you created a project called mywebsite, then in the command prompt, you have to specify the full path to mywebsite.

Once you have done this, then type in the following line shown below.



On a windows PC, you may have to use py instead of python, shown below.



Once, you have entered this line, the command prompt will ask you to create a username, enter your email address, and password twice. After you have done this successfully, the line, "Superuser created successfully" will be output.

This will be shown as such in the command prompt.

Command prompt admin setup for Django

Before we go to the actual admin screen of our Django website, the first thing you must do is make sure that the urls.py file in the project directory has a few things. It should look something like what is shown below.



So, in your urls.py file, there should be a few things.

There should be the line, from django.contrib import admin.

In the urlpatterns list, there should be the line, from django.contrib import admin.

This ensures that the website has an admin page.

So, now what you want to do is run your website on a local server. This is done by the line, py manage.py runserver.

This sets up your website on the local server.

Now, open your web browser and type in the line, http://127.0.0.1:8000/admin

This should bring you to the Django administration, where you can type in your username and password to login as the admin for the site.

Django administration page

Now, enter your username and password that you set up during the superuser creation.

Once, you have logged in, you can control groups, users, blog posts, etc.

And this admin feature is a key feature of Django.


Related Resources

How to Show All Tables of a MySQL Database in Python

How to Count the Number of Rows in a MySQL Table in Python



HTML Comment Box is loading comments...