Django Project Structure
A well-organized Django project separates concerns cleanly. Here's the structure this site uses and why.
The Layout
myproject/
├── manage.py # Entry point
├── myproject/ # Settings package
│ ├── settings.py
│ ├── urls.py # Root URL config
│ └── wsgi.py
├── core/ # Shared app (home, contact, etc.)
├── blog/ # Feature app
├── wiki/ # Feature app
├── templates/ # Project-level templates
│ ├── base.html
│ ├── core/
│ └── blog/
├── public/ # Static assets
│ ├── css/
│ ├── js/
│ └── images/
└── data/ # SQLite database
Key Principles
One app per domain. Each Django app owns one concept: blog handles posts, wiki handles docs, core handles the homepage and shared features. Apps should be loosely coupled.
Templates mirror apps. Templates live in a project-level templates/ directory, organized by app name. This makes them easy to find and override.
Static files in public/. Instead of per-app static directories, collect everything in one place. Use collectstatic for production.
Settings Organization
# settings.py — key decisions
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": BASE_DIR / "data" / "storydatabase.sqlite",
}
}
# Templates: project-level directory
TEMPLATES = [{
"DIRS": [BASE_DIR / "templates"],
...
}]
# Static files: single public directory
STATICFILES_DIRS = [BASE_DIR / "public"]
STATIC_URL = "/static/"
Management Commands
Custom commands live in <app>/management/commands/:
# blog/management/commands/sync_blog.py
from django.core.management.base import BaseCommand
class Command(BaseCommand):
help = "Sync blog posts from markdown files"
def handle(self, *args, **options):
# Your logic here
self.stdout.write(self.style.SUCCESS("Done!"))
Run with python manage.py sync_blog. Use call_command() to chain them in a master seeder.