4. Admin

In this lesson we are going to enable the Django admin panel so that we can add articles from the web interface.

Add the following code to my_blog/admin.py:

from django.contrib import admin

from .models import Article

admin.site.register(Article)

An admin panel has now been created so that you can add, edit, and delete articles.

Go to http://localhost:8000/admin/.

Oops! What is the password? Don't worry, we are going to create a superuser.

docker compose run --rm django python manage.py createsuperuser

Follow the instructions and you can now log in to the admin panel. You can make up the email, the important thing is that you remember the username and the password. Don't worry about your data, everything that happens between you and Django stays on your computer. You are storing all the information in your local database, specifically in a file called db.sqlite3 at the root of your project.

You can now add some articles. Go back to http://localhost:8000/admin/, use the username and password you created, and add some articles.

We recommend that you add some of the most important women in the history of computing:

There is no point in having data in a database if we don't display it on the web page.

Let's display the list you just inserted on the main page.

Building SPAs with Django and HTML Over the Wire: Learn to build real-time single page applications with Python

Building SPAs with Django and HTML Over the Wire: Learn to build real-time single page applications with Python

The HTML over WebSockets approach simplifies single-page application (SPA) development and lets you bypass learning a JavaScript rendering framework such as React, Vue, or Angular, moving the logic to Python. This web application development book provides you with all the Django tools you need to simplify your developments with real-time results.

Buy the book

Help me keep writing

Every coffee gives me a push toward the next article.

Comments

There are no comments yet.