React frontend and Django backend communication issue

I’m working on a web app for my final year project. The frontend is in React and the backend uses Django with SQLite. Everything seemed fine when the developer handed it over, but now I’m having trouble getting the frontend to talk to the backend.

The homepage loads okay, but that’s it. Clicking links just refreshes the homepage. Login always fails and signup just goes back to the homepage too.

I’ve tried a bunch of things:

  • Checked CORS settings
  • Made production builds
  • Double-checked urls.py

My process:

  1. npm run build for frontend
  2. Copy the build folder to the backend root
  3. Run npm start for frontend and py manage.py runserver for backend

Both run without errors, but only the homepage works on the frontend. The backend admin page and other Django pages work fine on their own.

I’m really stuck and my deadline is in 2 days. Any ideas what could be wrong? I’ve exhausted all my options even with ChatGPT’s help.

Here’s a snippet from my Django settings:

INSTALLED_APPS = [
    'django.contrib.admin',
    'rest_framework',
    'corsheaders',
    'api',
    # other apps...
]

CORS_ALLOWED_ORIGINS = [
    'http://localhost:3000',
    'http://127.0.0.1:8000',
    # other origins...
]

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}

Any help would be really appreciated!

hey, have u checked the network tab in dev tools? might show errors. are u using axios or fetch? baseURL might be off. try using a full url for one req. what type of app u building?

hey mate, sounds like a routing issue. check ur react router setup. make sure ur using the correct paths and components. also, double-check ur API endpoints in the frontend code. they might be pointing to the wrong URLs. good luck with ur project!