Project Structure

Understand the files Django generates and what each one does.

A fresh Django project has a small, predictable layout. Knowing what each file does saves confusion later.

FilePurpose
manage.pyCommand-line utility (runserver, migrate, etc.).
settings.pyAll project configuration.
urls.pyThe root URL routing table.
wsgi.pyEntry point for WSGI servers (production).
asgi.pyEntry point for ASGI/async servers.

Your project is made of one or more apps, each a self-contained folder of related features.

A Django project contains a settings package and one or more reusable apps, each app holding its own models, views and templatesProject: mysite/mysite/ (config)settings.pyurls.pywsgi.py / asgi.py__init__.pyblog/ (app)models.pyviews.pyurls.pymigrations/shop/ (app)models.pyviews.pytemplates/admin.pymanage.py — command-line utility for the whole project
One project wires together many small, reusable apps.

Example

Example · bash
mysite/
    manage.py
    mysite/
        __init__.py
        settings.py
        urls.py
        asgi.py
        wsgi.py

When to use it

  • A new Django developer learns which file to edit for URL routing by understanding the project structure.
  • A team lead explains the purpose of manage.py and the inner config package during code onboarding.
  • A developer knows to add apps to INSTALLED_APPS in settings.py after studying the project layout.

More examples

Project directory tree

Shows the files Django generates and the role each one plays in the project.

Example · bash
mysite/
  manage.py          # CLI entry point
  mysite/
    __init__.py
    settings.py        # project configuration
    urls.py            # root URL router
    asgi.py
    wsgi.py

Common manage.py commands

Lists the most frequently used manage.py sub-commands every Django developer needs daily.

Example · bash
python manage.py runserver
python manage.py makemigrations
python manage.py migrate
python manage.py shell

Root urls.py wires up apps

The root URLconf delegates URL prefixes to individual app URL modules using include().

Example · python
from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path("admin/", admin.site.urls),
    path("blog/", include("blog.urls")),
]

Discussion

  • Be the first to comment on this lesson.