Django Example
An example Django project. Includes:
- MIT license
- Dependency management with Poetry
- A custom User model
- Extensible local settings
- Example app using a namespaced URL
- Example model, view, and admin classes
- Example unit tests for models and views
- Example template tags
- Form-rendering with Crispy Forms
- Usage of ManifestStaticFilesStorage
- Example JS bundling with esbuild
- Example SCSS to CSS transpilation
- Code formatting with Black
- Dockerfile
- Terraform configuration for AWS with IPv6 support
- Roles for deployment via Ansible
- Support for ARM architecture
- Emails with AWS SES
- HTTPS support via Let's Encrypt
This project is tested on Python 3.10, but may support older Python versions.
Python Dependency Management with Poetry
To install the project's dependencies, first install Poetry and then run:
poetry install
Once installed, you can start a virtual environment with:
poetry shell
To create a requirements.txt
file for the production dependencies:
poetry export -f requirements.txt --output requirements.txt --without-hashes
Customized Bootstrap CSS via SCSS
A custom version of Bootstrap 5.1 can be produced by modifying custom.scss
in the static folder and then running:
npm run bootstrap
Backwards Compatible Javascript via esbuild
An example.js
files is included in the static directory. It can be built with:
npm run esbuild
Provision AWS Infrastructure via Terraform
Add a key named django-key
or change the key_name
variable.
The first run requires initializing with:
terraform init
Then (or on subsequent runs):
terraform plan --out=plan.tmp
terraform apply "plan.tmp"
The configuration is for the us-west-2
region. You can deploy to other region by changing the aws_region
and instance_ami
variables. Here is the list of available Ubuntu AMIs.
To destroy the provisioned infrastructure:
terraform plan -destroy --out=plan.tmp
terraform apply "plan.tmp"
Configure Server via Ansible
Add a deploy key to your Github repository.
Ansible variables that may need to be updated in site.yml
or in ansible-playbook
with the --extra-vars
flag:
- domain
- deploy_key
You can add your AWS access key to your current shell with:
ssh-add path/to/key.pem
You may need to add your current IP address to the AWS security group.
Ansible deployment is performed with:
ansible-playbook -e 'ansible_python_interpreter=python3' -i aws_ec2.yml -u ubuntu site.yml
Ansible inventory can be viewed with:
ansible-inventory -i aws_ec2.yml --list