manage.py is Django’s command-line utility. Every interaction with a project goes through it.
Core commands
# Start the development server
python manage.py runserver
python manage.py runserver 0.0.0.0:8000 # accessible on the network
# Migrations
python manage.py makemigrations # create migration files
python manage.py migrate # apply migrations
python manage.py showmigrations # status of all migrations
# Create an application
python manage.py startapp blog
# Superuser
python manage.py createsuperuser
# Interactive shell
python manage.py shell
python manage.py dbshell # SQL console
# Static files
python manage.py collectstatic # collect static files into STATIC_ROOT
makemigrations vs migrate
# makemigrations — only creates migration files (does not apply them)
python manage.py makemigrations tasks
# → tasks/migrations/0001_initial.py
# migrate — applies migrations to the database
python manage.py migrate
# → Applied tasks.0001_initial
shell — working with the ORM in the console
python manage.py shell
# Inside the shell
from tasks.models import Task
Task.objects.all()
Task.objects.create(title="Первая задача", status="todo")
Task.objects.filter(status="todo").count()
Checking the project
python manage.py check # check configuration
python manage.py check --deploy # check production readiness
Tests
python manage.py test # run all tests
python manage.py test tasks # tests for a specific app
python manage.py test tasks.tests.TaskModelTest
💬 Comments (0)
No comments yet
Be the first to share your opinion about this article!