Skip to content

Instantly share code, notes, and snippets.

@loicpw
Last active October 25, 2021 10:53
Show Gist options
  • Save loicpw/6e865122afff03c07a2eca63d0eaa202 to your computer and use it in GitHub Desktop.
Save loicpw/6e865122afff03c07a2eca63d0eaa202 to your computer and use it in GitHub Desktop.
Django manage cheatsheet

python manage.py

run test server

see also: runserver

default to http://127.0.0.1:8000/

python manage.py runserver

specify port

python manage.py runserver 8000

bind interfaces

python manage.py runserver 0:8000

Note

0 is a shortcut for 0.0.0.0.

create app

create new app (in the current dir)

python manage.py startapp <name>

migrations

init db / run migrations

python manage.py migrate

create migrations for <app name> app

python manage.py makemigrations <app name>

show migration SQL for <app name> and <migration name>

python manage.py sqlmigrate <app name> <migration name>

Note

model change steps:

  • Change your models (in models.py).
  • Run python manage.py makemigrations to create migrations for those changes.
  • Run python manage.py migrate to apply those changes to the database.

admin site

create root user for admin site (/admin)

python manage.py createsuperuser

run python shell

python manage.py shell

tests

run tests for the app <app name>

python manage.py test <app name>

miscellaneous

check for any issue in the project

python manage.py check
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment