Reputation: 369
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
Reputation: 4199
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.
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
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