Django Manage Commands Cheat Sheet

Django Manage Commands Cheat Sheet

A short cheat sheet for those who are familiar with Django, and need some reminder for useful Django commands.


May 18, 2022

Valeria Aynbinder

Valeria Aynbinder

Lecturer | AI- Expert | Entrepreneur | CTO

Installations

In order to get started with Django, all you need to do is install Django package using pip:

pip install django

After the installation is complete, you can move forward and create your Django application.


EduLabs ספק רשמי של הטכניון בנושאי תוכנה ובינה מלאכותית.

EduLabs

ספק רשמי של הטכניון

בנושאי תוכנה ובינה מלאכותית.



Django Application Creation

Creating a new Django web application consists of two stages: First, you need to create a new Django project:

django-admin startproject my_project

Note: my_project is a custom name for your project


Project tree after running startproject

Second, you need to create a new Django application that will sit inside the newly created project. In order to do this, you need to change directory to my_project (the one where manage.py file resides):

cd my_project python manage.py startapp my_app

Note: my_app is a custom name for your application After running this command your project tree will look similar to this:


Project folder after running startapp command

High tech workers earn more!

Up to 50% more money in a few weeks

Start your way in high-tech with an unfair advantage, exclusive knowledge, and the best connections!


Contact us!

DB management

Create migration

(this should be run after you make changes to your models.py):

python manage.py makemigrations

This command will result in creating a new migration file in your migrations folder:


Migration files inside migrations folder

SQL Migrate

(Review SQL queries that will actually run on your DB server during migrate)

python manage.py sqlmigrate my_app 0001

Note: my_app and 0001 are your app name and migration name respectively


Migrate

(this should be run when you want to apply changes in your migration files on your DB)

python manage.py migrate

Other useful commands

Create superuser

Use this command in order to create superuser that will allow you to login into Django Admin App

python manage.py createsuperuser


Django Shell

Use this command to start Django Shell with your application and models loaded (very useful when you want to play with Django models a bit)

python manage.py shell

Django has loaded your Django application for you, so now you can play with your Django models in Python shell!


Playing with Django Models in Django Shell

Originally published on Medium

Valeria Aynbinder

Valeria Aynbinder

Lecturer | AI- Expert | Entrepreneur | CTO


A leading expert in Artificial Intelligence with 15+ years of experience as a leader, lecturer, and entrepreneur. Passionate about new technology, teaching, and traveling.