logo

Essential Django Commands Cheat Sheet

O

Ohidur Rahman Bappy

MAR 22, 2025

Django 2.x Cheat Sheet

Setting Up Your Environment

Creating a Virtual Environment

Create a virtual environment for your Django app:

python -m venv ./venv

Learn more about virtual environments.

Activating the Virtual Environment

# Mac/Linux
source ./venv/bin/activate

# Windows
venv\Scripts\activate.bat

Deactivating the Virtual Environment

deactivate

Checking Installed Packages

pip freeze

Installing and Setting Up Django

Install Django

pip install django

Create a New Project

django-admin startproject PROJECTNAME

Running the Development Server

Run the server at http://127.0.0.1:8000:

python manage.py runserver

Creating a New App

python manage.py startapp APPNAME

Database Migrations

Create Migrations

python manage.py makemigrations

Apply Migrations

python manage.py migrate

Managing Static Files

Collecting Static Files

python manage.py collectstatic

List of Available Django Commands

Available subcommands:

[auth]
    changepassword
    createsuperuser

[contenttypes]
    remove_stale_contenttypes

[django]
    check
    compilemessages
    createcachetable
    dbshell
    diffsettings
    dumpdata
    flush
    inspectdb
    loaddata
    makemessages
    makemigrations
    migrate
    sendtestemail
    shell
    showmigrations
    sqlflush
    sqlmigrate
    sqlsequencereset
    squashmigrations
    startapp
    startproject
    test
    testserver

[sessions]
    clearsessions

[staticfiles]
    collectstatic
    findstatic
    runserver

Resetting Migrations

  1. Delete all database tables.
  2. Remove all migration files.

Run the following commands:

python manage.py migrate --fake
python manage.py makemigrations <app>
python manage.py migrate
python manage.py createsuperuser

This cheat sheet provides essential commands to kickstart your Django project efficiently. Always remember to read the official Django documentation for more in-depth information.