Django project template with many useful libraries and integrations included:
- Django with sqlite/postgresql database at backend
- Customized django_allauth app for login/signup flows. Optionally protect login/signup forms with Google ReCAPTCHA
- React, Bootstrap (optionally Tailwind CSS) at frontend
- NodeJS and Vite to build frontend and serve it on development
- WhiteNoise for cache serving (optionally via Nginx on production)
- Ansible deploy scripts to any server over SSH
- gunicorn
- nginx
- SQLite DB
- Simple create order application with PayPal payment button integration
- Several useful Python and JS utils
- Docker Compose setup with Dockerfiles for local development inside containers
- Emacs docker integration files
- Vagratfile to run VM if needed (for testing deployment, etc)
- Utilities
After bootsrtapping a project it creates a default core
application with homepage containing dummy React component with PayPal pay now button and backend API to handle payment
This is a starting point I use to develop my own projects. Completely opinionated. I use such setup for many years and used to it. It works great for running my projects as a solo developer. This will evolve with time.
Feel free to start a PR, I'm open to any new technology and if it works better then my current setup I would easily adopt it.
- Make sure you have Python >= 3.10 installed
- Install Django with
pip install django
, to have thedjango-admin
command available. - Open the command line and go to the directory you want to start your project in.
- Start your project in current directory using (
theprojectname
can only contain alphanumeric chars and underscore):django-admin startproject theprojectname . --extension=py,sh,sql --name=package.json,Dockerfile,hosts.inv,web.yml,docker-compose.yml,local_dev.env,Vagrantfile,.dir-locals.el --template=https://github.com/mylh/indiehacker-boilerplate/archive/refs/heads/master.zip
In the next steps, always remember to replace theprojectname
with your project's name
- Above: don't forget the
--extension
and--name
params! - Change the first line of README to the name of the project and update the rest of the file as needed
- If you use Emacs and docker: start emacs using
start_emacs.sh
script. It sets up ENV variables that are used to run emacs integration scripts inside docker containers. If you don't want to run containers make sure to delete.dir-locals.el
file.
- Adjust settings in
web/backend/theprojectname/settings/base.py
andweb/backend/theprojectname/settings/local.py
and secrets inweb/backend/local_dev.env
these are used in local development with docker - start development container with
docker compose up
and apply migrations by runningdocker compose exec -it web python manage.py migrate
- create django admin superuser
docker compose exec -it web python manage.py createsuperuser
- go to http://localhost:8000 and check that website is loading
Then start docker containers with
docker compose up
- Go to
ansible
directory and updatehosts.inv
with IP address and access credentials to your web server - Configure vars in
ansible/web.yml
- Add entry for
theprojectname-web
host in~/.ssh/config
- set
PROJECT_DOMAIN
inwev/backend/theprojectname/settings/production
and inansible/web.yml
- copy
app.env.example
intoapp.env
and update values as necessary - compile requirements.txt from requirements.in using pip-compile (locally or via container)
- build production static bundle by executing in frontend container
docker compose exec -it frontend npm run build
Run for full deployment including installation and configuration of all necessary services such as nginx, gunicorn, etc:
ansible-playbook -i hosts.inv web.yml
Code is deployed from local working copy of the repo. There is an option to deploy from Git. Configure variables in web.yml
, see ansible/deploy_django/defaults/main.yml
for details.
Following variables can be defined in web.yml that controls playbook behavior:
domain
- make sure to set it to correct domain before deploying, also update it insettings/base.py
purge_before_install
default False - deletes everything if any from targed directory at web serverclear_venv
default False - clears target venv before installationapp_user
defaultuser
. User to be created and used to run website at the webserverdeploy_from_local
default True - code is deployed from local working copydeploy_from_git
default False - deploy from Git repository that needs to be additionally configuredinstall_path
on serverinstall_ssl
default False if you need to use your own SSL certificate with nginx, put ssl cerificates into local/project_dir/ssl
directorynginx_basic_auth
default False - you can restrict access to deployed website, update user and password inansible/deploy_django/files/.htaccess
file, default areappuser:apppassword
nginx_serve_static
andnginx_serve_media
default False. Set to serve assets via nginx instead of whitenoiseinstall_geoip
default False if you need to install MaxMind GeoIP databaseapt_install
: list of addtional packages to be installed with apt, default:redis-server
install_cronjobs
: default False. Change to true and modify necessary cronjobs inansible/deploy_django/tasks/cronjobs.yml
Some tags are available to speed up deployment. To make reconfiguration of existing installation
ansible-playbook -i hosts.inv web.yml -t config
Quick update when only source code changed:
ansible-playbook -i hosts.inv web.yml -t deploy
Run in project dir:
vagrant up
Configure local ssh access by running
vagrant ssh-config >> ~/.ssh/config
Uncomment vagrant host in ansible/hosts.inv
Automatically convert input image into set of popular web-development icons sizes, produces output files as logo_256x256.png, etc
./convert_icons.sh logo.png