How to create a simple blog using Django 3 - part 4

/ #Django

It's time to see one more of the reasons why Django is so great. Let's check out the Django admin interface.

Creating a user

In order to sign in to the admin interface, we need to add a user. We do this using the command line. Go to the root of the Django project and run the following command:

$ python createsuperuser

This will take you through a short create-user-wizard. Just fill in your details and you should be ready to sign in :-)

Signing in to the admin interface

The only step left is to start the webserver again:

$ python runserver

Open a web browser and go to "" where you can sign in with the username and password you just created.

When you're signed in, you'll see that the only available models to work with are "Users" and "Groups". These to will always be there. If you want to change something with your user, just click "Users" and find your username in the list.

Registering our models

Django know what apps we have added to the list of installed apps in, but Django still doesn't know which models we want to show in the admin interface.

Open "blog/" in your editor and add the following code:

# Import the models
from .models import Category, Post

# Register the models

If you go back to the admin interface again and refresh the browser, a new container should be showing links to "Categorys" and "Posts". Feel free to click around and check out the category and post we created earlier in this series.

If you think it looks stupid with "Categorys" instead of "Categories", there is a way to fix this. Open "blog/" in your editor and change the "Meta" class of the "Category" model:

class Meta:
	ordering = ('title',)
	verbose_name_plural = 'Categories'

If you refresh your browser now, "Categorys" should be replaced with "Categories".


Now that you know how to sign in to the admin interface and how to register models there, it's time to spend some time becomming more familiar with it. Try to add a couple of new categories and posts.

In the next part of this series we'll start creating the templates for our blog. See you :-)

How to create a simple blog using Django 3 series

Part 1 - Installation
Part 2 - File structure
Part 3 - Database models
Part 4 - Admin interface
Part 5 - Creating some templates
Part 6 - Views and URLs
Part 7 - Category views
Part 8 - Media files
Part 9 - Comments
Part 10 - Search


No comments yet...

Add comment

Subscribe to my newsletter