Todo API is an project for me to learn how to use the django in python and how to dockerize the project
There are currently 3 services in use: the api (Django App), the db (the postgrSQL database), and the nginx (Nginx configuration). - api: The Django Dockerfile is in the root directory, and it has an entrypoint file that connects the backend to the database and runs migrations as well as collects the statics. - db: This is built from the postgres:13-alpine image. The default environment variables are set in the docker-compose.yml file. - nginx: The default configuration for nginx is inside the nginx folder in the nginx.conf file.
-
Clone the repo:
git clone https://github.com/farasjibran/django-rest-api
-
Configure the environment variables.
- Copy the content of the example env file that is inside the django-rest-api folder into a .env file:
cp .env.example .env
- The new .env file should contain all the environment variables necessary to run all the django app in all the environments. However, the only needed variables for docker to run are the following:
SECRET_KEY DB_NAME DB_USER DB_PASSWORD DB_HOST DB_PORT
- For the database, the default configurations should be:
DB_NAME=db_todos DB_USER=todos_user DB_PASSWORD=todos_password! DB_HOST=db DB_PORT=5432
- The DOCKER_SECRET_KEY is the django secret key. To generate a new one see: Stackoverflow Link
- Copy the content of the example env file that is inside the django-rest-api folder into a .env file:
-
Run docker-compose:
docker-compose up --build
-
Congratulations =) !!! The App should be running in localhost:80
-
(Optional step) To create a super user run:
docker-compose run api ./manage.py createsuperuser
-
Clone the repo:
git clone https://github.com/farasjibran/django-rest-api
-
Configure a virtual env and set up the database. See Link for configuring Virtual Environment and Link for Database setup.
-
Configure the environment variables.
- Copy the content of the example env file that is inside the django-rest-api folder into a .env file:
cp .env.example .env
- The new .env file should contain all the environment variables necessary to run all the django app in all the environments. However, the only needed variables for the development environment to run are the following:
SECRET_KEY DB_NAME DB_USER DB_PASSWORD DB_HOST DB_PORT
- For the database, the default configurations should be:
DB_NAME=todo_app DB_USER=postgres DB_PASSWORD= DB_HOST=localhost DB_PORT=5432
- The SECRET_KEY is the django secret key. To generate a new one see: Stackoverflow Link
- Copy the content of the example env file that is inside the django-rest-api folder into a .env file:
-
Run the migrations and then the app:
python manage.py migrate python manage.py runserver
-
Congratulations =) !!! The App should be running in localhost:8000
-
(Optional step) To create a super user run:
python manage.py createsuperuser
- Setup Database: Digital Ocean Link for Django Deployment on VPS
- Docker Oficial Documentation
- Dockerizing Django, PostgreSQL, guinicorn, and Nginx:
- Github repo of sunilale0: Link
- My repo to Dockerize Django + Postgresql + Nginx + React js: Ceci-Aguilera/django-react-nginx-mysql-docker
- Michael Herman article on testdriven.io: Link
- Django Official Documentation
- Generate a new secret key: Stackoverflow Link
- Modify the Django Admin:
- Small modifications (add searching, columns, ...): Link
- Modify Templates and css: Link from Medium
- Django Rest Framework Official Documentation
- More about Nested Serializers: Stackoverflow Link
- More about GenericViews: Testdriver.io Link
- Create Virual Environment with Virtualenv and Virtualenvwrapper: Link
- Configure CORS
- Setup Django with Cloudinary