Quick reference for how to make a website with django, following Django's tutorial:
- System-wide:
docker
,docker-compose
,python3
,django
- Installed in project's python virtual environment:
django
,psycopg2
- Recommended (project python venv):
wheel
,pylint
,redgreenunittest
django-admin startproject [appname]
(use "app", "base", or "config" instead of project name to avoid django's default of nesting a directory with the same name, and allow hyphens in project name. See discussion on django forums)- rename project directory to [project name]
python3 -m venv env
(Create venv)source env/bin/activate
(Activate venv)pip install django
(Install django in venv)
- Make docker-compose.yml in project directory, specifying default database name (e.g.,
postgres_dev
) (Template) - Run docker.service (depends on:
docker
) sudo docker-compose up
(compose database; keep this process running while developing)- (Later, set up a separate databse for production)
- Open app/settings.py
- Set
DATABASES
to match docker-compose.yml (Template) python manage.py migrate
(Make initial migrations)
pip install psycopg2
python manage.py runserver
- Preview site in browser at localhost:8000 (runserver's default port)
sudo docker compose up
(Run the docker container)source env/bin/activate
(Enter python virutal environment)python manage.py runserver
- Preview site in browser at localhost:8000
- Change models (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.
pip install pylint
(If using nvim/nvim-coc as IDE)pip install redgreenunittest
- In app/settings.py, add:
TEST_RUNNER="redgreenunittest.django.runner.RedGreenDiscoverRunner"
python manage.py createsuperuser
- Navigate to admin site: localhost:8000/admin
- Make the app modifiable by admin, by adding to [app name]/admin.py:
from django.contrib import admin
from .models import [ModelName]
admin.site.register([ModelName])