liveBook · Manning

Settings.py

As explained in Django in Action

settings.py is the Django project configuration module containing declarations that define project behavior.

settings.py is the Django project’s configuration script: a Python file of variable declarations that control Django’s behavior. It lives in the project configuration directory alongside urls.py, wsgi.py, and asgi.py. Think of it as the place where Django learns the project’s rules rather than guessing them. section 2.2 section 2.9

A newly created project already contains many settings. One important setting is INSTALLED_APPS, a list of string names for Django apps. Creating an app creates Python files, but does not activate the app; add its name to INSTALLED_APPS so Django recognizes it as an app instead of merely another module. section 2.4

Listing 2.1 Tell Django about your home app
# RiffMates/RiffMates/settings.py
...  #1
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'home',  #2
]
...

Add the home app’s name to INSTALLED_APPS after Django’s built-in apps. This explicit registration lets Django distinguish project apps from ordinary Python modules. section 2.4

Configure a logout destination

Settings also provide project-wide choices outside app registration. Set LOGOUT_REDIRECT_URL to the URL Django should use after logout; here, the band listing URL is used because a home page has not yet been built. LOGIN_REDIRECT_URL appears alongside it for account-management redirects. section 6.4.1

The development server reports which settings module it loaded, such as RiffMates.settings. That is a useful sanity check: Django is running with the configuration file you expect, not one hiding in a different project directory. section 2.2

How Django in Action covers it

How deep it goes
Defines settings.py as Python declarations and works through INSTALLED_APPS and redirect values without detailing the full settings catalog.
Examples
Uses the RiffMates home app registration and redirects logout to a band listing URL.
What it assumes
Introduces it from zero after creating a Django project and app skeleton.
What you can do after
Operate/configure it by registering Django apps and choosing a logout destination.
How it connects
Connects Django projects with apps, INSTALLED_APPS, urls.py, views, and authentication redirects.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Django in Action. The section links point to the parts of the book it draws on.