liveBook · Manning

Django configuration directory

As explained in Django in Action

A Django configuration directory is the project package containing modules that define URL mappings, project settings, and other generated configuration.

A Django project has an outer project folder and an inner configuration directory, which usually has the same name. That duplicate naming is easy to trip over: RiffMates/RiffMates is the package holding project-wide setup, not a second application. section 2.2

RiffMates/
├── RiffMates
│   ├── __init__.py
│   ├── asgi.py
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
└── manage.py

The inner directory contains the generated configuration modules, while manage.py stays in the outer project directory. section 2.2

Create this directory with django-admin startproject. Django generates urls.py for URL mappings, settings.py for project settings, and WSGI-related setup; the generated layout also includes asgi.py and __init__.py. Every Django website needs its own project configuration files. section 2.2

Keep the two directory roles distinct:

  • The outer project directory is the working folder: it contains manage.py, which runs project control and configuration commands. section 2.2
  • The inner configuration directory is a Python package containing project-wide modules such as settings.py and urls.py. section 2.2
  • Apps hold website code such as views; register an app through INSTALLED_APPS in settings.py and map its views through urls.py. section 2.9

Finding RiffMates settings

After running django-admin startproject RiffMates, look for RiffMates/RiffMates/settings.py when Django reports that it is using RiffMates.settings. Use the outer RiffMates/manage.py to run commands such as runserver. section 2.2

How Django in Action covers it

How deep it goes
Explains the generated directory layout and names its configuration modules without detailing their contents.
Examples
Uses the nested RiffMates/RiffMates layout and its generated file tree.
What it assumes
Starts with creating a Django project through django-admin startproject.
What you can do after
Operate/configure it by locating settings.py and urls.py and running project commands through manage.py.
How it connects
Connects Django projects to django-admin, manage.py, settings.py, urls.py, apps, views, and URL mapping.

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.