Django Commands Cheat Sheet
Sidebar
Programming · Django Commands Cheat Sheet
The commands for an everyday Django project, starting with a copy-and-paste sequence that creates my_project from nothing. Every command in the sequence is preceded by pwd so you can see which directory you are in before it runs. Written against Django 6.1.
Start Here: A New Project From Nothing (Linux)
# Run these in order, one at a time. After each "pwd", compare the path with the "expect" note. # 1. Make the project folder (works from any directory) pwd mkdir -p /home/philip/Projects/my_project # 2. Go into it. Every later step runs from here unless it says otherwise. pwd cd /home/philip/Projects/my_project # 3. Create the virtual environment, a folder named .venv inside the project pwd # expect: /home/philip/Projects/my_project python3 -m venv .venv # 4. Activate it. Your prompt should now start with (.venv) pwd # expect: /home/philip/Projects/my_project source .venv/bin/activate # 5. Upgrade pip inside the venv (a new venv often ships an old one) pwd # expect: /home/philip/Projects/my_project python -m pip install --upgrade pip # 6. Install Django into the venv pwd # expect: /home/philip/Projects/my_project pip install django # 7. Create the project. The dot at the end means "here", so manage.py lands in this folder pwd # expect: /home/philip/Projects/my_project django-admin startproject my_project . # 8. Create an app called blog. Run it where manage.py is pwd # expect: /home/philip/Projects/my_project ls # expect to see manage.py in the list python manage.py startapp blog # 9. Register the app: edit my_project/settings.py and add 'blog' to INSTALLED_APPS (not a command) # 10. Create the database tables for Django's built-in apps pwd # expect: /home/philip/Projects/my_project python manage.py migrate # 11. Create an admin login (it asks for a username, email and password) pwd # expect: /home/philip/Projects/my_project python manage.py createsuperuser # 12. Save the package list so the environment can be rebuilt pwd # expect: /home/philip/Projects/my_project pip freeze > requirements.txt # 13. Start the development server, then open http://127.0.0.1:8000/ (Ctrl+C stops it) pwd # expect: /home/philip/Projects/my_project python manage.py runserver
What You End Up With
my_project/ # the folder you made (the "project root") ├── .venv/ # the virtual environment ├── manage.py # the command runner ├── requirements.txt ├── db.sqlite3 # appears after migrate ├── my_project/ # the project's configuration package │ ├── __init__.py │ ├── settings.py │ ├── urls.py │ ├── asgi.py │ └── wsgi.py └── blog/ # the app ├── migrations/ ├── admin.py ├── apps.py ├── models.py ├── tests.py └── views.py
Coming Back Another Day
cd /home/philip/Projects/my_projectGo to the project root firstsource .venv/bin/activateLook for (.venv) at the start of the promptpython manage.py runserverStart the serverdeactivateLeave the venv when you are finishedpip install -r requirements.txtOn a fresh clone: after creating and activating a new venvThe Development Server
python manage.py runserverServes on 127.0.0.1:8000 and restarts when you save a filepython manage.py runserver 8001Use a different portpython manage.py runserver 0.0.0.0:8000Reachable from other devices; add the host to ALLOWED_HOSTS if you get a 400Ctrl+CStop the serverpython manage.py checkLook for configuration problems without starting anythingpython manage.py check --deploySecurity checklist for production (a new project reports 8 warnings)Apps
python manage.py startapp shopCreates the folder shop/ with models, views, admin, tests and migrations'blog'Add this string to INSTALLED_APPS in settings.py after creating an appdjango-admin startproject name .Project: only once, and with the dot to avoid an extra nested folderpython manage.py startapp --helpOptions, including --templateModels and Migrations
python manage.py makemigrationsAfter changing a model: writes the migration filespython manage.py makemigrations blog -n add_bodyOnly for one app, with your own name for the filepython manage.py migrateApplies every unapplied migration to the databasepython manage.py showmigrations[X] applied, [ ] not yetpython manage.py sqlmigrate blog 0001Prints the SQL a migration would runpython manage.py migrate blog zeroUndoes all of one app's migrationspython manage.py makemigrations --check --dry-runChanges nothing; exit code 1 if a migration is missing (useful in CI)Users and the Admin
python manage.py createsuperuserPrompts for username, email and passwordpython manage.py changepassword adminReset a user's passwordpython manage.py createsuperuser --noinput --username admin --email a@b.comFor scripts, with no prompts: set DJANGO_SUPERUSER_PASSWORD in the environment first (worked here)/admin/The admin site's URL: http://127.0.0.1:8000/admin/python manage.py clearsessionsDeletes expired sessionsThe Shell and Data
python manage.py shellPython prompt with Django loaded; it imports your models for youpython manage.py shell -c "..."Run one line of Python and exitpython manage.py dumpdata blog --indent 2 > blog.jsonExport an app's rows as JSONpython manage.py loaddata blog.jsonImport them againpython manage.py inspectdbPrint model code for an existing database's tablespython manage.py flushEmpties every table (it asks first). Keeps the tablespython manage.py dbshellOpens the database's own client (needs sqlite3 installed; not run here)Tests
python manage.py testRuns every test in the projectpython manage.py test blogOnly one apppython manage.py test blog.tests.PostTests.test_createOne test methodpython manage.py test -v 2Verbose: shows each test and the database setuppython manage.py test --keepdbReuse the test database between runspython manage.py test --parallelSpread tests across processes"NO TESTS RAN"A new app has an empty tests.py; test names must start with test_Static Files
STATIC_ROOT = BASE_DIR / 'staticfiles'Add to settings.py first, or the next command failspython manage.py collectstaticCopies every app's static files into STATIC_ROOT (130 for a new project)python manage.py collectstatic --noinputWithout the yes/no promptpython manage.py findstatic admin/css/base.cssShows which file Django would serve for a pathSettings Worth Knowing
python manage.py diffsettingsLists the settings that differ from Django's defaultsDEBUGTrue in development onlySECRET_KEYGenerated for you and marked django-insecure-; replace and keep out of git for a real siteALLOWED_HOSTSMust list your domain once DEBUG is offDATABASESSQLite file db.sqlite3 by defaultpython manage.py helpLists every command available; help <command> for onePackages and the venv
pip install djangorestframeworkInstall into the active venv onlypip freeze > requirements.txtRun again whenever you add a packagepython -m django --versionCheck the installed Django versionpip list --outdatedSee which packages have newer versions.gitignoreAdd .venv/, db.sqlite3, staticfiles/ and __pycache__/Troubleshooting
django-admin: command not foundThe venv is not active. Check the prompt for (.venv) and run the activate linecan't open file 'manage.py'Wrong directory. Run pwd and ls; you need the folder that contains manage.pyNo module named 'django'Not installed in this venv, or a different Python is running. Check which pythonYou have N unapplied migration(s)Run python manage.py migrateThat port is already in use.Another server is running (or use a different port: runserver 8001). The wording comes from Django's source; I did not trigger it hereModel or template of a new app is ignoredThe app is not in INSTALLED_APPSensurepip is not availableDebian/Ubuntu: install the python3-venv package, then repeat step 3 (from general knowledge, not run here)The three questions behind most beginner errors
Which directory am I in (pwd, and does ls show manage.py)? Is the venv active (the (.venv) prefix)? Did I add the app to INSTALLED_APPS? Almost every "it does nothing" or "command not found" message in this sheet is one of those three.
What was checked on this sheet
I ran the commands from "Start here" onward in a scratch project with Python 3.14.0 and Django 6.1.2 on Windows 11 (startproject, startapp, makemigrations, migrate, createsuperuser, shell, dumpdata, loaddata, test, collectstatic, findstatic, diffsettings, check, clearsessions, flush (declined at its prompt), runserver with real requests, including a 400 for an unknown host on 0.0.0.0). Not run: the Linux-specific steps (mkdir -p, python3 -m venv, source .venv/bin/activate and the /home/philip/... paths, which differ only in syntax from Windows), dbshell (no sqlite3 program here), and the port-in-use error.