Introduction
In this article, we shall use a database for the first time to build a basic Message Board App where users can post and read short messages.
Initial Setup
At this point, we should be getting a bit familiar with the initial setup for a Django project so we can quickly run through the standard initial setup commands to begin a new one. We need to do the following:
- Create a new directory for our code called mb.
- Install Django in a new virtual environment.
- Create a new project called mb_project.
- Create a new app called posts.
- update settings.py.
In a new command line console, enter the following commands:
mkdir mb && cd mb
pipenv install django==3.0.1
pipenv shell
django-admin startproject mb_project
python manage.py startapp posts
Next, we need to alert Django to the new app, posts, by adding it to the bottom of the INSTALLED_APPS section of our settings.py file. To do this, we need to do the following:
mb_project/settings.py
INSTALLED_APPS = [
‘django.contrib.admin’
‘django.contrib.auth’
‘django.contrib.contenttypes’
‘django.contrib.sessions’
‘django.contrib.messages’
‘django.contrib.staticfiles’
‘posts.apps.PostsConfig’,
]
Then execute the migrate command to create an initial database on Django’s default server. To do this, type the following command in the command prompt: