This is a Cookiecutter template for generating opinionated Django projects. It's not a Django application itself, but rather a template that generates Django applications with various configurable features.
To avoid confusion when working on issues, PRs, and documentation:
- Root, cookiecutter, and generator project: refers to the cookiecutter project that lives in the root folder and generates the Django project
- Generated and Django project: refers to the project generated by cookiecutter
- Root directory: Contains the Cookiecutter configuration and template files
{{cookiecutter.project_slug}}/: The actual Django project template that gets generatedcookiecutter.json: Configuration file defining template variables and optionstests/: Test suite for validating template generation
- Cruft (Recommended): Cruft is compatible with Cookiecutter and is the recommended method for creating projects because it allows updating the generated project with the latest template changes using
cruft update - Cookiecutter: Standard method for generating projects, but doesn't support updates
The main configuration options in cookiecutter.json:
project_name: Name of the generated project (default: "API")project_slug: URL-friendly version of project namegithub_username: GitHub username for repository URLsdatabase: Choose between "PostgreSQL" or "SQLite"api: API framework options ("No", "Django Ninja", "Django Ninja CRUD")html: HTML approach ("Default", "HTMX", "No")css: CSS framework ("Bootstrap", "No")deploy: Deployment options ("No", "Docker", "Heroku", "Render")use_sentry: Boolean for Sentry error trackingstaticfiles: Boolean for static file handling
The template creates Django projects with:
- Custom User model in isolated
usersapp - Django Extensions for development utilities
- Python Decouple for settings management
- dj-database-url for database configuration
- Pre-commit hooks with Black, Ruff, yamlfmt, actionlint
- pytest-django, pytest-mock, and model_bakery for testing
- GitHub Actions CI/CD pipeline
- API: Django Ninja for REST APIs with CRUD operations
- HTML: HTMX for dynamic frontend interactions
- CSS: Bootstrap styling
- Database: PostgreSQL (with Docker) or SQLite
- Deployment: Docker, Heroku, or Render configurations
- Monitoring: Sentry integration for error tracking
- Static Files: WhiteNoise for serving static files
- Files in
{{cookiecutter.project_slug}}/use Jinja2 templating - Conditional files use
{% if cookiecutter.option %}blocks - Variable substitution uses
{{ cookiecutter.variable_name }}
project_name/
├── project_slug/ # Main Django project
│ ├── settings.py # Django settings
│ ├── urls.py # URL configuration
│ ├── core/ # Core application
│ └── users/ # Custom user model
├── manage.py # Django management script
├── pyproject.toml # Python dependencies
└── .github/ # CI/CD workflows
- Update
cookiecutter.jsonwith new configuration options - Add conditional template files in
{{cookiecutter.project_slug}}/ - Create tests in
tests/to validate the new feature - Update the README.md with feature documentation
- Use
pytest-cookiesfor testing template generation - Each configurable feature should have dedicated tests
- Test both inclusion and exclusion of optional features
- Tests are located in
tests/test_*.pyfiles
- Follow Black formatting for Python code in templates
- Use Ruff for linting Python code
- Template files should maintain consistent indentation
- Conditional blocks should be clearly commented
- Dependencies: Keep dependencies in alphabetical order in pyproject.toml templates
{% if cookiecutter.use_feature %}
# Feature-specific code here
{% endif %}{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/settings.py
# Using python-decouple for configuration
from decouple import config
DEBUG = config('DEBUG', default=False, cast=bool)def test_feature(cookies):
result = cookies.bake(extra_context={'feature': 'value'})
assert result.exit_code == 0
# Validate generated files- Optional dependencies are included based on configuration
- Main documentation is in
README.md - Feature-specific documentation should be included in generated project README
- Keep the features list in README.md synchronized with
cookiecutter.json
# Install dependencies
poetry install --no-root
# Run all tests
poetry run pytest tests/ -v
# Test specific feature
poetry run pytest tests/test_feature.py -v
# Generate a project locally for testing (using cruft - recommended)
cruft create . --no-input
# Generate a project locally for testing (using cookiecutter)
cookiecutter . --no-inputThis template follows Django best practices and conventions while providing flexibility for different project requirements.