Project
django-admin startproject <name>
Create a project
Add a trailing . to use the current directory instead of a new
folder.
python manage.py startapp <app>
Create an app in the project
Then add it to INSTALLED_APPS in settings.
python manage.py check
Run system checks
python manage.py check --deploy
Check production settings
django-admin startproject <name> --template
<url>
Start from a project template
Templates can run code; inspect before use.
python manage.py diffsettings
Settings that differ from defaults
django-admin --version
Print the Django version
Generated layout
Path
Purpose
manage.py
project command runner
<name>/settings.py
configuration
<name>/urls.py
root URL routes
<app>/models.py
database models
<app>/views.py
request handlers
<app>/migrations/
schema history
Run
python manage.py runserver
Start the dev server
Auto-reloads on code changes.
python manage.py runserver <port>
Use another port
python manage.py runserver 0.0.0.0:8000
Listen on all interfaces
Needs the host in ALLOWED_HOSTS.
python manage.py runserver --noreload
Disable auto-reload
python manage.py shell
Python shell with Django set up
python manage.py shell -c "<code>"
Run one Python statement
python manage.py dbshell
Open the database client
python manage.py createsuperuser
Create an admin user
python manage.py changepassword <user>
Change a user's password
Migrations
python manage.py makemigrations
Create migrations from model changes
python manage.py migrate
Apply pending migrations
python manage.py makemigrations <app>
Limit to one app
python manage.py showmigrations
List migrations and applied state
python manage.py makemigrations --dry-run
Preview without writing files
python manage.py makemigrations --check
Fail if migrations are missing
Useful in CI.
python manage.py migrate <app>
<migration>
Migrate to a given point
Use zero to unapply all of an app.
python manage.py sqlmigrate <app>
<migration>
Print a migration's SQL
python manage.py makemigrations --empty <app>
Empty migration for custom work
python manage.py migrate --plan
Show what migrate would do
python manage.py migrate --fake <app>
<migration>
Mark applied without running
Only when the schema already matches.
python manage.py squashmigrations <app>
<migration>
Squash into fewer migrations
Tests
python manage.py test
Run all tests
python manage.py test
<app>.tests.<Class>.<method>
Run one test
python manage.py test --keepdb
Reuse the test database
python manage.py test --parallel
Run tests in parallel
python manage.py test --failfast
Stop at first failure
python manage.py test -k <pattern>
Run tests matching a name
python manage.py test --pdb
Debugger on error or failure
python manage.py test --debug-sql
Show SQL for failing tests
python manage.py test --tag <tag>
Run tests with a tag
Static & i18n
python manage.py collectstatic
Gather static files for deployment
Needs STATIC_ROOT set.
python manage.py collectstatic --noinput
Run without prompts
python manage.py findstatic <path>
Where a static file resolves
python manage.py makemessages -l <lang>
Extract translatable strings
python manage.py compilemessages
Compile .po to .mo
python manage.py clearsessions
Delete expired sessions
python manage.py sendtestemail <address>
Test the email setup