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-admincommand available. - Open the command line and go to the directory you want to start your project in.
- Start your project in current directory using (
theprojectnamecan 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
--extensionand--nameparams! - 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.shscript. 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.elfile.
- Adjust settings in
web/backend/theprojectname/settings/base.pyandweb/backend/theprojectname/settings/local.pyand secrets inweb/backend/local_dev.envthese are used in local development with docker - start development container with
docker compose upand 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
ansibledirectory and updatehosts.invwith IP address and access credentials to your web server - Configure vars in
ansible/web.yml - Add entry for
theprojectname-webhost in~/.ssh/config - set
PROJECT_DOMAINinwev/backend/theprojectname/settings/productionand inansible/web.yml - copy
app.env.exampleintoapp.envand 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.pypurge_before_installdefault False - deletes everything if any from targed directory at web serverclear_venvdefault False - clears target venv before installationapp_userdefaultuser. User to be created and used to run website at the webserverdeploy_from_localdefault True - code is deployed from local working copydeploy_from_gitdefault False - deploy from Git repository that needs to be additionally configuredinstall_pathon serverinstall_ssldefault False if you need to use your own SSL certificate with nginx, put ssl cerificates into local/project_dir/ssldirectorynginx_basic_authdefault False - you can restrict access to deployed website, update user and password inansible/deploy_django/files/.htaccessfile, default areappuser:apppasswordnginx_serve_staticandnginx_serve_mediadefault False. Set to serve assets via nginx instead of whitenoiseinstall_geoipdefault False if you need to install MaxMind GeoIP databaseapt_install: list of addtional packages to be installed with apt, default:redis-serverinstall_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