A repository that shows a Django backend with a React frontend.
This repository shows how to set up a Django backend with a React frontend. It includes a simple Todo application with a REST API.
To get started with this project, follow these steps:
-
Clone the repository:
git clone https://github.com/emanuelefavero/django-react.git cd django-react
Set up a virtual environment:
make virtualenv Tip: @see Makefile for all available commands。Install the required packages:
make installAdd Django .env variables in the root .env file:
SECRET_KEY= # Run `utils/generate_secret_key.py` to generate a new key
DEBUG= # Set to False in production, True for developmentAdd React .env variables in the frontend/.env file:
NEXT_PUBLIC_SERVER_URL=http://localhost:8000 # Set to your Django server URL
NEXT_PUBLIC_CLIENT_URL=http://localhost:3000 # Set to your React client URLRun the Django and React development servers:
make runNow you should have both the Django backend and the React frontend running. You can access the API at http://localhost:8000/api/todo/ and the React app at http://localhost:3000/.
Tip: You can also run the backend and frontend separately using
make runserverandmake runclient(after opening a new terminal window for the client).
- GET /api/todo/ - Retrieve a list of todos
Note: More API endpoints will be added in future updates
Make sure to run python manage.py makemigrations and python manage.py migrate to apply database migrations after making changes to the models.
Resources
from https://github.com/emanuelefavero/django-react
No comments:
Post a Comment