Django Commands Cheat Sheet

FARSHAD K
2 min readFeb 16, 2024

--

django

Django, a high-level Python web framework, provides a set of management commands that help you perform various tasks during the development and management of a Django project. Here’s a comprehensive list of Django management commands along with brief descriptions of their features:

startproject: Creates a new Django project.

django-admin startproject projectname

startapp: Creates a new Django app within a project.

python manage.py startapp appname

runserver: Starts the development server.

python manage.py runserver

shell: Opens the Python shell with Django environment loaded.

python manage.py shell

makemigrations: Generates new database migration files based on model changes.

python manage.py makemigrations

migrate: Applies database migrations to synchronize the database schema.

python manage.py migrate

createsuperuser: Creates a superuser for the Django admin.

python manage.py createsuperuser

collectstatic: Gathers static files from your apps into a single directory.

python manage.py collectstatic

test: Runs tests for your Django project.

python manage.py test

dbshell: Opens a command-line interface to the database.

python manage.py dbshell

check: Checks for issues in your project without making migrations or touching the database.

python manage.py check

showmigrations: Displays a list of all migrations and their status.

python manage.py showmigrations

shell_plus: Enhanced version of the shell with additional features (requires django-extensions).

python manage.py shell_plus

dumpdata: Outputs the contents of the database as a JSON or XML fixture.

python manage.py dumpdata

loaddata: Loads data from a fixture into the database.

python manage.py loaddata

flush: Resets the database by removing all data.

python manage.py flush

createsuperuser: Creates a superuser for the Django admin.

python manage.py createsuperuser

startapp: Creates a new app within a Django project.

python manage.py startapp appname

runserver: Starts the development server.

python manage.py runserver

runscript: Runs a Python script in the context of a Django project (requires django-extensions).

python manage.py runscript script_name

graph_models: Creates a visual representation of your Django models (requires django-extensions).

python manage.py graph_models -a > models.dot

dbshell: Opens a command-line interface to the database.

python manage.py dbshell

shell_plus: Enhanced version of the shell with additional features (requires django-extensions).

python manage.py shell_plus

test: Runs tests for your Django project.

python manage.py test

check: Checks for issues in your project without making migrations or touching the database.

python manage.py check

check — deploy: Checks for common issues in a deployment-ready project.

python manage.py check --deploy

show_urls: Displays all URLs defined in the project.

python manage.py show_urls

These are some of the commonly used Django management commands. Note that some commands may require additional packages or settings, and the availability of certain commands may depend on your Django project’s configuration and installed packages.

--

--

FARSHAD K
FARSHAD K

Written by FARSHAD K

Learning data science and machine learning with a strong curiosity in AI technologies and a drive to stay ahead in innovation.

No responses yet