Django .gitignore template
The Django template covers Python bytecode and virtual environments, plus the four things the framework itself creates: local settings, a SQLite database, uploaded media and collected static output.
At a glance
- Category
- Framework
- Patterns in this template
- 13 rules
- Directories ignored
- 5 of the 13 rules end in a slash, so they match directories only
- Also needs an OS template
- Yes. Nothing here matches file manager or editor artefacts.
- Typical companions
- Python for the fuller cache and packaging rules, plus an OS template.
In detail
local_settings.py is the framework's oldest convention for keeping secrets out of the repository. The shared settings module ends with an import of it, wrapped so that a missing file is not an error, and the local file supplies the database password, the secret key and any debug toggles. Ignoring it is the whole point of the pattern.
db.sqlite3 and its journal file are the development database. It is created by running migrations and populated by whatever you did while developing, which means a committed copy carries real rows: test users with hashed passwords, sample records, and sometimes data copied from production for debugging. It is also binary, so every commit of it is a full rewrite.
media is where user uploads land. It is populated at runtime rather than at build time, it can grow without limit, and its contents belong to users rather than to the project. staticfiles is the opposite case: it is the output of the collection command, which copies static assets from every installed application into one directory for the web server to serve. Both sides of the static pipeline exist, and only the source side belongs in git.
The Python rules underneath are the familiar ones: __pycache__, *.pyc, the *.py[cod] class, and the virtual environment directories. *.pot files are translation templates extracted from the source, regenerated by a management command, while the compiled .mo files are covered by the fuller Python template rather than this one.
What this template does not do is cover the packaging and test caches that a real project accumulates. Pairing it with the Python template gives you .pytest_cache, .coverage, .mypy_cache and the egg-info directories, none of which appear here. That pairing is the normal choice, and it is also why the generator lets you tick more than one template at a time rather than making you pick the closest single match.
Examples
*.log
*.pot
*.pyc
__pycache__/
local_settings.py
db.sqlite3
db.sqlite3-journal
media/
staticfiles/
*.py[cod]
.env
.venv/
venv/13 lines exactly as the tool writes them, before any common additions you tick.
Things that catch people out
- Ignoring db.sqlite3 after it has been committed leaves every previous version in the history, including any real data that was in it at the time.
- The rule is media/ with a trailing slash and no anchor, so an app level media directory is covered too. If your project serves a tracked media fixture, that fixture disappears.
- This template does not ignore staticfiles' source directories, and it should not: the static folder inside each app is source, only the collected output is generated.
Try it: .gitignore Generator
Pick one or more templates, tick the common additions you want, and copy or download the combined .gitignore.
.gitignore Generator
LOCAL · Browser-OnlyGenerate comprehensive .gitignore files by combining templates for languages, frameworks, IDEs, and operating systems
Language
Framework
IDE
OS
Build Tool
Infrastructure
Common Additions
Preview
Select templates or common additions to generate a .gitignore file.
Related .gitignore templates
All .gitignore templates →Python .gitignore template
A line by line read of the Python .gitignore template: bytecode caches, virtual environments, packaging output, test caches and the lib/ rule that bites.
Flask .gitignore template
The Flask template adds the instance folder to the usual Python rules, which is the framework's designated place for configuration that must not be committed.
Rails .gitignore template
The Rails template is built around the encrypted credentials system: the encrypted file is committed, the key that decrypts it never is. Every rule explained.
Spring Boot .gitignore template
The Spring Boot template covers both build tools at once and adds sections for three IDEs, which makes it broad but leaves application secrets uncovered.
.NET .gitignore template
The .NET template covers bin, obj and NuGet output, and ignores launchSettings.json, which holds the launch profiles and environment variables for local runs.
Flutter .gitignore template
The Flutter template adds generated plugin manifests and per platform build artefacts to the Dart rules, including the iOS pod directory and build modes.
Tools for this
- .gitignore Generator Generate .gitignore files for any project - 50+ templates for languages, frameworks, IDEs, and OS
- .env Editor & Validator Edit and validate .env files online - detect duplicates, mask secrets, generate .env.example