Django

Settings & Production Configuration

Settings split (base/dev/prod), secrets management, ALLOWED_HOSTS, CSRF_TRUSTED_ORIGINS, SECURE_* settings, .env/vault, storage configuration

22 pytań z rozmów·
Senior
1

What is the recommended structure for organizing Django settings files in production?

Odpowiedź

The recommended structure involves creating a settings package with a base.py file containing common configurations, then separate dev.py, staging.py and prod.py files that import and extend base.py. This approach allows sharing common configuration while customizing specific environments, making maintenance easier and reducing code duplication.

2

How to specify which settings file to use when starting a Django project?

Odpowiedź

The DJANGO_SETTINGS_MODULE environment variable specifies the Python path to the settings module to use. For example, DJANGO_SETTINGS_MODULE=myproject.settings.prod tells Django to use the prod.py file from the settings package. This variable can be set in the shell, server configuration files or deployment scripts.

3

What is the purpose of the ALLOWED_HOSTS setting in Django?

Odpowiedź

ALLOWED_HOSTS is a list of domains/hosts allowed to serve the Django application. This security mechanism protects against HTTP Host header attacks by validating the Host header of each request. In production with DEBUG=False, this setting is mandatory and must contain the legitimate domains of the application to avoid 400 Bad Request errors.

4

What ALLOWED_HOSTS value accepts any host, and why is it dangerous in production?

5

What is the purpose of the CSRF_TRUSTED_ORIGINS setting introduced in Django 4.0?

+19 pytań z rozmów

Opanuj Django na następną rozmowę

Uzyskaj dostęp do wszystkich pytań, flashcards, testów technicznych, ćwiczeń code review i symulatorów rozmów.

Zacznij za darmo