Using Models

A model is a class that represents a database table. It defines the structure, fields, and behavior of the data stored in the table. By default, Django uses SQLite as its database engine, which is a lightweight, file-based database that doesn’t require additional setup. However, if you can use other database engines such as MySQL.

In this example we’re going to use a model to create a blog post application for our website. Navigate to the directory where the project was created. For example, my project is in the directory myweb

cd pyweb

Create a new app called blog. Run the following command

python manage.py startapp blog

Next, we need to define our model. In the app directory (blog), open the models.py file

from django.db import ...

Get Python Made Easy now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.