Search⌘ K
AI Features

Creating the Config App with Django

Explore how to create and configure the Django Config app within your backend service. Understand the purpose of essential files such as settings.py and urls.py, perform migrations, and prepare your project for Dockerization and database connection using MySQL.

The Config app content

Previously, we created our project inside the backend directory by running the django-admin, startproject, and config commands. If we navigate to this backend directory, we'll see a folder named config, which the django-admin automatically created for us. Inside this folder are the manage.py and db.sqlite3 files and another folder with the same name as the outer folder. This inner config folder is a Python package, which is our Config app.

The illustration below shows the content of our project folder, which contains our Config app.

The Config app content
The Config app content

Let’s look at what all these files do:

  • The outer config/ folder: This is the project folder created by Django. Django does not alter the name of this folder, so we can rename it to whatever we want. Later, we'll rename it to backendservice1.

  • The inner config/ folder: This is the inner project folder and our Config app. It is a Python package that we do not rename.

  • The __init__.py file: This is a Python file inside the inner config/ that tells the Python interpreter that our Config app is an actual Python package.

  • The asgi.py file: This helps web servers compatible with the Asynchronous Server Gateway Interface serve our project.

  • The settings.py file: This will contain all of our Django project settings.

  • The urls.py file: This will contain all of our project’s URLs/endpoints.

  • The wsgi.py file: This Python file helps web servers compatible with the Web Server Gateway Interface serve our project. It helps with deployment during production.

  • The manage.py file: This outer config/ file helps us execute several Django commands in the command line for our project.

  • The db.sqlite3 file: This is an SQLite database file inside the outer config/ folder. We won't use this file since we'll use the MySQL database.

Although there are a lot of files, we'll only work with the settings.py and urls.py ones.

Exploring the settings.py and urls.py files

The settings.py and urls.py are two important files in our Config app. The behavior of our project is dependent on the settings.py file. So we need to be familiar with it. As we develop our project and add components, we'll always return to the settings.py file to make adjustments. Similarly, as we define and add routes, we must update the urls.py file.

Now, let's take some time to explore these two files, focusing on the highlighted lines. Also, click the “Run” button to apply migrations before the application dockerization.

NOTE: At any point in this course, if you get an error or a warning on the widget’s output the first time you click the “Run” button, click the “Run” button again.

Exploring the Config app content