This project consists of a Django backend and a React frontend. It was created as an example project for my video about deploying Django-React apps on a Linux VPS available at https://youtu.be/E9Ly_rASuS8.
backend/ # Django project
frontend/ # React project
- Navigate to the backend directory:
cd backend
- Create a virtual environment:
python -m venv venv
- Activate the virtual environment:
- On Windows:
venv\Scripts\activate
- On macOS and Linux:
source venv/bin/activate
- Install required packages:
pip install -r requirements.txt
- Create database
- Set up environment variables:
Create a
.env
file with the following content:SECRET_KEY='django-secret-key' DEBUG=True SESSION_COOKIE_SECURE=False CSRF_COOKIE_SECURE=False ALLOWED_HOSTS=localhost DATABASE_URL=postgres://appuser:asd123123@127.0.0.1:5432/appdb CSRF_TRUSTED_ORIGINS=http://localhost:3000,http://localhost:8000
- Run migrations:
python manage.py migrate
- Start the Django development server:
python manage.py runserver
- Navigate to the frontend directory:
cd frontend
- Install dependencies using Bun:
bun install
- Start the development server:
bun run dev
- To build the project:
bun run build
- To run linting:
bun run lint
- The frontend uses Vite as the build tool and development server.
- TypeScript is used in the frontend project.
- The backend uses PostgreSQL as the database. Make sure to have PostgreSQL installed and running with the appropriate credentials as specified in the
DATABASE_URL
environment variable. - CSRF protection is enabled for the frontend-backend communication.
- Start the Django backend server.
- Start the React frontend development server.
- Access the application at
http://localhost:3000
.
Note: Make sure both the backend and frontend servers are running simultaneously for the full application to work.