django Administrator Page

2019-06-03

let's see how to use the administrator page that django basically provides

Outline

I try to use python django for serverside developing. in this blog post, I’ll instroduce how to use the administrator page that django basically provides. django administrator page looks like phpadmin which means we can see and manage the database information on the page.

this blog is a series. if you want to check other blog posts of the series, see the links below.

also, this blog series source code is opened on Github. you can see full source code via the link below.

Configure Language

if you want to change the default language of the administrator page that django basically provides, open django_exercise/settings.py file and modify it like below.

...
# LANGUAGE_CODE = 'en-us'
LANGUAGE_CODE = 'fr'
...

in here, I’ll use the default Englisth setting.

Create Superuser

we need to create a superuser for using the django administrator page. execute the django command below to create a superuser.

# source venv/bin/activate
# pip install -r requirements.txt
# cd django_exercise
# python manage.py migrate
python manage.py createsuperuser

after executing, you can see the superuser registration procedure.

venv > ~/django_exercise/django_exercise > python manage.py createsuperuser
Username (leave blank to use '...'): dev-yakuza
Email address: dev.yakuza@gmail.com
Password:
Password (again):
Superuser created successfully.

insert the information what you want to create for the superuser.

Connect Administrator Page

use the URL below to go to the django administrator page.

# python manage.py runserver
http://127.0.0.1:8000/admin

if you’ve done well, you can see the page like below.

django administrator page - login

and then, insert the user information created above, and login. you can see the screen like below after sign-in

django administrator page - main page

Register Models To Administrator Page

we need to register our Models to manage it on the django administrator page. open blog/admin.py file and modify it like below to register our Post Models. if you want to know how to make django Models, see the previous blog post.(Use Models in django)

from django.contrib import admin
from .models import Post

admin.site.register(Post)

and then, refresh the administrator page. you can see the Models we created in there like below.

django administrator page - display the Models on the administrator page

Write Blog Post via Administrator Page

let’s try to write a blog post via the django administrator page. click Add button on the left of Posts in the bottom of BLOG like below

register data via django administrator page - select the models on the administrator page

write a test data like below.

register data via django administrator - register a test data

and then, cleck Save and add another to add an additional data for testing. at this time, insert published_at data, too.

register data via django administrator - add test data

at this time, click Save button to go to the data list screen.

register data via django administrator - test data list

you can see the data stored well like above.

Check

one more time, we’ll use a database tool for checking the data is really stored well.

register data via django administrator page - check the data via database tool

we can see the data that we created via django administrator stored well.

Completed

we’ve seen how to use django administrator page, and also we’ve seen how to display the models we’ve created before. now, we can manage the data without database tools.

Buy me a coffeeBuy me a coffee
Posts