Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Projects and Apps  ›  Lesson

Projects and Apps

Projects & Apps 14 minA Django project is the whole site with its settings, while an app is a self-contained feature package inside it, created with startapp and switched on in INSTALLED_APPS.

Projects and Apps

Django uses two words that sound alike and mean different things. The project is the whole cookbook website. An app is one feature inside it, such as recipes. Keep them straight and every folder in a Django codebase makes sense.

The rule

One project per site; one app per feature.

With the environment active, create the project. The final dot means "put it in the current folder":

django-admin startproject cookbook .
cookbook/            <- the folder you made earlier
├── manage.py        <- the command tool for this project
└── cookbook/        <- the project's Python package
    ├── __init__.py
    ├── settings.py  <- configuration for the whole site
    ├── urls.py      <- the site's root table of URLs
    ├── asgi.py      <- entry point for async servers
    └── wsgi.py      <- entry point for classic servers

Now create an app for the first feature:

python manage.py startapp recipes
recipes/
├── __init__.py
├── admin.py       <- show models in the admin site
├── apps.py        <- the app's configuration class
├── migrations/    <- database change history
├── models.py      <- data
├── tests.py       <- tests
└── views.py       <- request handlers

An app does nothing until you switch it on in settings.py:

INSTALLED_APPS = [
    "django.contrib.admin",
    "django.contrib.auth",
    # ...the other built-in apps...
    "recipes",
]

Notice that the built-in admin and login system are apps too. Django itself is assembled the same way you will build the cookbook.

The shortcut

Describe the feature in one sentence without the word "and". If you can, it is one app. "Recipes and reviews" becomes two apps: recipes and reviews. Each can be read, tested and even reused on its own.

Laying out the cookbookStep 1 of 4
  1. The project

    django-admin startproject cookbook . makes manage.py and the cookbook settings package.

The most common slip: creating the app and forgetting INSTALLED_APPS. Django then ignores the app's models, and makemigrations reports "No changes detected".

Drills

Answer fast — trust the rule.

quick drill

Which command creates a new app called reviews inside an existing project?

quick drill

What does the trailing . in django-admin startproject cookbook . do?

quick drill

You made the recipes app and wrote a model, but makemigrations says "No changes detected". Most likely cause?

quick drill

Which file does startapp NOT create?

Remember

  • One project per site; one app per feature.
  • startproject once, startapp per feature, then add it to INSTALLED_APPS.
  • Trap: a forgotten INSTALLED_APPS line makes the app invisible.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainProject or app?

The cookbook will have recipes, user reviews and a shopping list. Explain how you would divide this into a Django project and apps, give the commands to create them, and say what step people most often forget after creating an app.