Manage Local Development and Remote Production Environment

As the last topic of this course, we'll explain how to efficiently manage the local development environment and the remote production environment. When you launch your new web service and work with other developers, you'll need to manage both environments simultaneously. As explained earlier, there are three key points in managing the differences between the deployment and production environments.

  1. Do not share irrelevant files (.gitignore)
  2. Do not install irrelevant dependencies (requiremetns.txt)
  3. Do not set irrelevant configurations (settings.py)

This sounds easy, but it is troublesome in practice. Here, we'll summarize the key approaches using our case.

Requirements

We haven't yet explained how to differentiate the requirements files for development and production. We can use the same approach as the one used for settings files. Create the requirements directory and add three files to manage requirements: base.txt, development.txt, and production.txt. Here are the examples of the three files used in our app example.

base.txt

Rename the original requirements.txt, and keep the requirements that are commonly used for both environments.

requirements/base.txt
Django==4.1.7
django-crispy-forms
crispy-bootstrap5
django-allauth
django-environ

development.txt

In our case, we are not using any specific library for development. Just get the list from base.txt by writing -r base.txt.

requirements/development.txt
-r base.txt

production.txt

Use