A modern full-stack application with React frontend and Django backend, configured for both development and production environments.
sitestore/
├── backend/ # Django backend
│ ├── api/ # API app with models, views, serializers
│ ├── config/ # Django project settings
│ └── manage.py
├── frontend/ # React frontend (Vite)
│ ├── src/
│ └── package.json
└── README.md
- ✅ React frontend with Vite
- ✅ Django REST Framework backend
- ✅ CORS configured for development
- ✅ Production-ready configuration
- ✅ Example CRUD API (Items)
- ✅ Modern, responsive UI
- Python 3.8+
- Node.js 16+ and npm/yarn
- Virtual environment (recommended)
-
Navigate to backend directory:
cd backend -
Create and activate virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Create
.envfile:cp .env.example .env
Edit
.envand set yourSECRET_KEY:SECRET_KEY=your-secret-key-here DEBUG=True ALLOWED_HOSTS=localhost,127.0.0.1 CORS_ALLOWED_ORIGINS=http://localhost:5173,http://localhost:3000 CORS_ALLOW_ALL_ORIGINS=True
-
Run migrations:
python manage.py makemigrations python manage.py migrate
-
Create superuser (optional):
python manage.py createsuperuser
-
Navigate to frontend directory:
cd frontend -
Install dependencies:
npm install # or yarn install
Terminal 1 - Django Backend:
cd backend
source venv/bin/activate # On Windows: venv\Scripts\activate
python manage.py runserverBackend will run on http://localhost:8000
Terminal 2 - React Frontend:
cd frontend
npm run devFrontend will run on http://localhost:5173
- Hot Module Replacement (HMR) - React changes update instantly
- Proxy Configuration - Vite proxies
/apirequests to Django backend - CORS Enabled - Backend allows requests from frontend origin
- Separate Servers - Frontend and backend run independently
GET /api/health/- Health checkGET /api/items/- List all itemsPOST /api/items/- Create new itemGET /api/items/<id>/- Get item detailsPUT /api/items/<id>/- Update itemDELETE /api/items/<id>/- Delete item
-
Build React frontend:
cd frontend npm run buildThis creates a
dist/folder with optimized production build. -
Configure Django for production: Update
backend/.env:DEBUG=False SECRET_KEY=your-production-secret-key ALLOWED_HOSTS=yourdomain.com,www.yourdomain.com CORS_ALLOW_ALL_ORIGINS=False CORS_ALLOWED_ORIGINS=https://yourdomain.com
-
Collect static files:
cd backend python manage.py collectstatic --noinput -
Run Django server:
python manage.py runserver
Or use a production server like Gunicorn:
pip install gunicorn gunicorn config.wsgi:application
- Single Server - Django serves both API and React app
- Optimized Build - React app is minified and optimized
- Static File Serving - Django serves React static assets
- Security - CORS restricted, DEBUG disabled
- Django serves React build files
- Single server deployment
- Good for small to medium applications
- Deploy React to CDN (Vercel, Netlify, etc.)
- Deploy Django to cloud (Heroku, AWS, etc.)
- Update CORS settings to allow frontend domain
- Ensure
django-cors-headersis installed - Check
CORS_ALLOWED_ORIGINSin settings - Verify frontend URL matches CORS configuration
- Run
python manage.py collectstatic - Check
STATIC_ROOTandSTATICFILES_DIRSin settings - Verify file permissions
- Check backend is running on port 8000
- Verify proxy configuration in
vite.config.js - Check browser console for errors
MIT