Search⌘ K
AI Features

Database and Media Files Setup

Understand how to set up and configure PostgreSQL as your Django database, manage static files like CSS and JavaScript, and handle user-uploaded media files. This lesson helps you configure crucial settings in your Django project for both development and production environments.

SQLite 3 database setup


The default database used by Django is the SQLite3 database. The following piece of code is generated whenever we set up a new Django web app.

SQLite
Python
...
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
...

PostgreSQL database setup


In this course, we’ll be using the PostgreSQL database. To use the PostgreSQL database, we need to modify the DATABASES field in the settings.py as follows:

PostgreSQL
Python
...
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': '<database_name>',
'USER': '<database_username>',
'PASSWORD': '<database_password>',
'HOST': 'localhost',
'PORT': '<port>',
}
}
...

ENGINE

Refers to the database component used to perform CRUD (Create, Read, Update, Delete) operations on the database data.

NAME

Refers to the name of the database.

...