Using the django-admin startporject --template
flag, I wanted to create my projects with a lot of the tedious work already done.
I create a project and then find and replace the project name with the django
context keyword {{ project_name }}
. I use the same keyword in my makefile
, environment variables, dockerfile
, etc.
When I run the startproject
command with the --template
flag, django
copies all the files in the directory of my template. This includes a test folder, api
route folders, and makes a copy of the remaining files under the folder.
I then do a find and replace to replace {{ project_name }}
in the non django
files which aren’t parsed by django-admin startproject
and I’m ready to go.
I generate a secret key using:
python -c 'from django.core.management.utils import get_random_secret_key; \
print(get_random_secret_key())'
And insert it into my example.env file, before running:
# Edit the example.env as needed
cp example.env .env
An example of a setup, with redis
, celery
, postgres
, and api
ready is on my github page.
#source BugBytes - Django - Using Startproject and StartApp Templates