skip to Main Content

I am doing my first project with Django and React. Whenever i run

npm run dev

the project compiles succesfully. But once I go to the browser, it says that the site can’t be reached and that

localhost rejected the conection.

I tried running

PORT=8001 npm run dev

but the same keeps happening.

I have read other options about changing the webpack.config.js file, like this

devServer: {
    contentBase: path.join(__dirname, 'dist'),
    compress: true,
    port: 3000,
    open: true,
  },

but my project has no dist folder

2

Answers


  1. React and Django must be different projects running in different ports.

    By default react runs in on port 3000 with the command npm run dev and django on 8000 with the command python manage.py runserver.

    Then you can develop your front-end and back-end separately like that:

    Front-end: localhost:3000

    Back-end: localhost:8000

    Login or Signup to reply.
  2. When you run the frontend, it will give a success message in terminal and with the port url like:

    Local: http://localhost:3000
    On Your Network: http://192.168.1.100:3000

    Make sure to copy the local one and paste it on your browser.

    Django Server port after python manage.py runserver:
    Starting development server at http://127.0.0.1:8000/

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search