Abhiram P Jayan
Abhiram P Jayan

Reputation: 369

how to combine or integrate reactjs and Django

I created front end in Reactjs and backend in Django and linked using Django rest API. but react runs in localhost:3000 and Django in localhost:8000. How to combine or integrate these two and runs in the same address.

Upvotes: 2

Views: 2171

Answers (2)

rrebase
rrebase

Reputation: 4199

Development

If you are in the development phase and using Create React App then you can add "proxy": "http://localhost:8000" to your package.json. Then your api requests done in React will be forwarded to port 8000.

Production

The production setup is quite different. You'll want to run yarn build and let either Django itself or nginx serve the index.html. In that case there won't be multiple ports anymore since the React build is just static files.

I am creating an example real world project as we speak with the same stack (GitHub). It doesn't have production setup quite ready yet, but you can see my development setup if you want some inspiration.

Upvotes: 1

Anurag
Anurag

Reputation: 1

You need to link them using the routes you created in your backend. Put the routes in fetch requests in React frontend and call them via GET or POST methods etc. Your users will only hit the frontend host address once you deploy your application to the server.

Upvotes: 0

Related Questions