Django 2.x Cheat Sheet
Creating a virtual environment
We need to create a virtual env for our app to run in: More Here
Run this command in whatever folder you want to create your venv folder
python -m venv ./venv
Activate the virtualenv
# Mac/Linux
source ./venv/bin/activate
# Windows
venv\Scripts\activate.bat - May need to add full path (c:\users\....venv\Scripts\activate.bat)
Escape from venv
deactivate
Check packages installed in that venv
pip freeze
Install Django
pip install django
Create your project
django-admin startproject PROJECTNAME
Run Server (http://127.0.0.1:8000) CTRL+C to stop
python manage.py runserver
Create an app
python manage.py startapp APPNAME
Create migrations
python manage.py makemigrations
Run migration
python manage.py migrate
Collect Static Files
python manage.py collectstatic
List of available 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
Django reset migrations
- Delete all tables
- Delete all migrations files
python manage.py migrate --fake
python manage.py makemigrations <app>
python manage.py migrate
python manage.py createsuperuser