liveBook · Manning

Django project

As explained in Django in Action

A Django project is the site-level structure and configuration that contains application code and interacts with a web server to handle visits.

A Django project is the site-level structure for a website. It is the framework-managed outline that receives visits through a web server and invokes your code to produce responses. Unlike a library, where your code controls execution order, Django supplies the execution paths; your code plugs into them. section 2.1 section 2.2

Create a separate project for each new site, before adding pages. The project starts as a minimal generated Python program in a directory you name. Use an isolated virtual environment first to avoid package conflicts, install Django, then run `django-admin startproject RiffMates .` to create the project in the current directory. section 2.1 section 2.2

A generated project

A RiffMates project contains `manage.py` alongside a same-named configuration directory. That directory includes `settings.py` for configuration, `urls.py` for URL mappings, and `wsgi.py` as the generated interface between a web server and Django. Run `python manage.py runserver` to start the development server; its output identifies the local URL and any unapplied migrations. section 2.2 section 2.9

Figure 2.1 A web server invokes Django through WSGI, Django calls your code, and then it formats the response for a browser
figure

Follow the request path: a web server calls Django through WSGI, Django calls project code, and the response is formatted for the browser. section 2.2

Keep the project as the site container, not the dumping ground for every page. URLs map to views, but putting all views in the project-level `urls.py` soon becomes unwieldy. Put website code into Django apps—Python-module-based units within the project. A project needs at least one app; larger sites can use several self-contained apps, and a web server can host multiple projects when URL routing distinguishes them. section 2.3 section 2.9

The project coordinates the main pieces of a simple page request:

  • A browser visits a URL, which the project routes through `urls.py` to a view. section 2.2 section 2.9
  • A view in an app accepts an `HttpRequest` and returns an `HttpResponse` containing browser content. section 2.9
  • Register each app in `INSTALLED_APPS` within `settings.py` so Django knows it belongs to the project. section 2.9

How Django in Action covers it

How deep it goes
Explains creation, generated files, WSGI request flow, development-server use, and app organization without requiring WSGI internals.
Examples
Uses the RiffMates site, its generated directory tree, `startproject`, and `runserver` output as concrete artifacts.
What it assumes
Teaches project setup from Django installation and virtual environments while treating generated WSGI details as unnecessary in development.
What you can do after
Build it from scratch by creating a project, starting its development server, and placing page code in registered apps.
How it connects
Connects projects with Django apps, URL routing, views, WSGI, web servers, settings, and HTTP request-response objects.

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.