Quick Start
One-liner (Windows):
mkdir mysite && cd mysite && python -m venv venv && venv\Scripts\activate.bat && pip install django && django-admin startproject mysite . && python manage.py migrate && set "DJANGO_SUPERUSER_PASSWORD=admin" && python manage.py createsuperuser --noinput --username admin --email admin@example.org && python manage.py runserver
One-liner (macOS, Linux):
mkdir mysite && cd mysite && python -m venv venv && source venv/bin/activate && pip install django && django-admin startproject mysite . && python manage.py migrate && export DJANGO_SUPERUSER_PASSWORD=admin && python manage.py createsuperuser --noinput --username admin --email admin@example.org && python manage.py runserver
Step-By-Step Tutorial
Create a new folder for the project:
mkdir mysite
cd mysite
Create a virtual environment:
python -m venv venv
venv\Scripts\activate.bat (Windows)
source venv/bin/activate (macOS, Linux)
Virtual environments isolate projects, allowing each one to have its own set of dependencies (packages & Python version).
Install Django and create a new project:
pip install django
django-admin startproject mysite .
The startproject command generates a basic project structure. "mysite" is merely an arbitrary folder name containing the main configuration files. The dot (.) creates the project in the current folder.
Run migrations and create a superuser:
python manage.py migrate
python manage.py createsuperuser
The "migrate" command synchronizes the database with the current state of your Django project's models. A model defines the structure and behavior of a database table, enabling you to manage databases with Python.
Run the development server:
python manage.py runserver
Visit http://127.0.0.1:8000/
You can login to admin in here: http://127.0.0.1:8000/admin/