Django React Starter project with virtualenv dev environment and key Django dependencies, auth, etc. configured. It is ready to be deployed to render. Get started in minutes.
- Django with Django Rest Framework
- Auth: Django AllAuth + Google Social Login (if desired)
- Runtime: Virtualenv & Docker-Compose
- Python: 3.12
- DB: Postgres
- Frontend: React (with Create-React-App). Axios is configured to connect to Django (CORS, token auth, etc.)
- Backend Testing: backend tests with Pytest
- Background Tasks: Django Background Tasks
- Deployment: Render PaaS Platform via render.yml
You can install these prerequisites with brew.
- Python 3.12 -
brew install [email protected]
- pre-commit -
brew install pre-commit
- Replace all occurrences of 'myapp' with shorthand name for this app
- This includes
.env
file,docker-compose.yml
,render.yml
- This includes
-
Start a virtual environment python -m venv .venv
-
Activate the virtual environment source .venv/bin/activate
-
Install requirements pip install -r server/requirements.txt
-
Start the db and other services make start_db
-
Run migrations and create initial user make init
-
Start the server. Go to (localhost:8000)[localhost:/8000] make start_server
-
Load sample data, run:
make load_sample_data
You can view the server at (localhost:8000)[localhost:/8000]. You can view Django Admin and db at (localhost:8000/admin)[localhost:8000/admin]. Login with admin/Admin123.
-
In the
frontend
directory: npm run build -
Then: npm run start
You can view the server at (localhost:3000)[localhost:/3000].
For a quick start, you can use the docker-compose file. Take a look at its contents to see what is included.
-
Create
.env
file from.env.template
.- Modify
REPO_ROOT
variable in .env file with path to your repo folder.
- Modify
-
docker-compose build
to build the container. -
docker-compose up -d
Start web and postgres. For the first time, wait for a minute for postgres to be up, you may need to restart the web container withdocker-compose restart web
. -
Go to localhost:8000 and login with username
admin
and passwordadmin123
.
To stop the containers use docker-compose stop
or docker-compose stop <service-name>
.
For debugging, you may want to a have bash session in the dev container.
-
docker-compose exec web bash
will open a bash session in the web container. -
You can also adjust
command
in docker-compose.yml and set it tobash -c "tail -f /dev/null"
. This will have the container just run in the background rather than starting the webserver upon start. -
python manage.py runserver 0.0.0.0:8000
This will start the webserver.
This section breaks down everything that is handled by docker-compose.yml.
docker-compose build
Runs the Dockerfile to build the Django container with all the dependencies. Follow the steps in Dockerfile to build you custom environment if you would like.
If you look at the command
section in docker-compose.yml, you will see that it runs most of the commands below for the initial setup.
-
python manage.py makemigrations <app-name>
andpython manage.py migrate
. These commands prepare and apply database migrations, which create the database tables for the models we add to Django. You need to run this every time you add or modify a model that requires changes to a database table. -
python manage.py load_sample_data
. Creates the admin user and triggers the load sample data command. You need to implement this yourself if you want to load any data at startup in your dev environment. See load_sample_data.py. -
python manage.py runserver 0.0.0.0:8000
Starts the webserver. -
python3 manage.py shell
Starts a python shell with Django apps loaded. Very helpful for development. For more details on this, see iPython or Django shell docs. -
The main Django app is app, which has files for views, modules etc. See views.py for view definitions, templates for html files and templates and urls.py for urls. See Django docs for more details.
This is managed via Render PaaS platform.
-
Go to Render and start a project.
-
Create a new blueprint and point it to this repo and its
render.yml
. It will automatically pull, build, and deploy the images. -
There 2-3 environment variables you need to manually overwrite. See
render.yml
for details.
Initial deployment should be done in 10-15 minutes.