Basic commands for working with Django

April 19, 2020

Recently I've started working a lot with Django (this website plus a few other projects I have in the works), but I am always forgetting a couple of the commands and have to look them up.

So I thought I would gather the commands I forget together (plus the other basic commands for completion) so I have a place to look them up quickly, and thought they might be useful to others as well.

Virtual environments

Creating a virtual environment:
python -m venv <path>

Activate the virtual environment:
source <path>/bin/activate

Django basics

Install Django
pip install Django

Create a project:
django-admin startproject <project name>

Create an app:
python startapp <app name>


Prep the DB migration:
python makemigrations <(optional) list of apps>

Migrate the DB changes:
python migrate <(optional) list of apps>


Creating the super user:
python createsuperuser

Reset a user's password:
python changepassword <username>

Other Commands

Run the project:
python runserver <(optional) server details>
Server details can just be the port (default 8000), or address and port in the form - localhost is also a valid value for address.

Run the shell:
python shell