This is a Python Django Quickstart for Nullstone. This is based off the official Writing your first Django app guide.
This quickstart is set up with:
- Python 3.9
- Django 4
- Create a public web app. (Remember
app-name
for later) - Add a subdomain. (this will add a Load Balancer capability)
- Provision
nullstone up --wait --block=<app-name> --env=<env-name>
- Build, push, and deploy
docker build -t django-quickstart .
nullstone launch --source=django-quickstart --app=<app-name> --env=<env-name>
You can run this project locally inside Docker or using a dev server. The docker setup is configured to hot reload; you don't have to rebuild/restart the container when you change code.
docker compose up
Visit http://localhost:9000.
poetry run ./manage.py runserver
Visit http://localhost:8000.
- Install django using
pip install django
. - Run
django-admin startproject app .
- Add dependencies to
requirements.txt
.
asgiref ~= 3.5.1
django ~= 4.0.4
sqlparse ~= 0.4.2
tzdata ~= 2022.1
- Configure
settings.py
withDJANGO_DEBUG
# DEBUG = True
DEBUG = os.environ.get('DJANGO_DEBUG', '') != 'False'
- Configure
settings.py
withSECRET_KEY
SECRET_KEY = os.environ.get('SECRET_KEY', default='default-key')
- Add
ALLOWED_HOSTS
from Nullstone.
NULLSTONE_PUBLIC_HOSTS = os.environ.get('NULLSTONE_PUBLIC_HOSTS')
if NULLSTONE_PUBLIC_HOSTS:
ALLOWED_HOSTS.append(NULLSTONE_PUBLIC_HOSTS)
NULLSTONE_PRIVATE_HOSTS = os.environ.get('NULLSTONE_PRIVATE_HOSTS')
if NULLSTONE_PRIVATE_HOSTS:
ALLOWED_HOSTS.append(NULLSTONE_PRIVATE_HOSTS)
- Add private IP address into
ALLOWED_HOSTS
.
ECS_PRIVATE_IPS = os.environ.get('ECS_PRIVATE_IPS')
if ECS_PRIVATE_IPS:
ALLOWED_HOSTS.append(ECS_PRIVATE_IPS)