Mihai Domocos
Brașov Get in touch
Chapter 1

Project setup and settings

A Django project laid out for deployment from day one: settings split by environment, secrets read from the environment, and a repository that is ready for the chapters that follow.

What this chapter covers

This chapter is being written. It walks through the project layout used for the rest of the course, the settings package split into base, local and production modules, and the environment variables that keep secrets out of the repository.

Until the full text lands, the code below shows the shape of the production settings module you will end up with.

python
1# config/settings/production.py
2import os
3from .base import * # noqa: F401,F403
4
5DEBUG = False
6SECRET_KEY = os.environ["DJANGO_SECRET_KEY"]
7ALLOWED_HOSTS = os.environ.get("DJANGO_ALLOWED_HOSTS", "").split(",")
8
9CSRF_TRUSTED_ORIGINS = [f"https://{h}" for h in ALLOWED_HOSTS if h]
10SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")

Before you start

  • Python 3.12 and a recent Django installed locally
  • A GitLab account for the CI/CD chapter
  • A small Linux server you can SSH into, from any provider

This site remembers your theme choice and, with your consent, uses cookies for analytics. Cookie policy