Home > Software design >  Django-React integration Django port does not actualize
Django-React integration Django port does not actualize

Time:11-05

I made changes to the src/app.js when I use npm start inside the react_app, in port 3000 changes and gets rendered but when I do that using python manage.py runserver I only see the default react-app welcome how can I fix that?

views

from django.contrib import admin
from django.urls import path
from . import views

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', views.index, name='index')
]

Heres is my react_app inside my django project here is the app.js

import "./App.css";

function App() {
  return (
    <div className="App">
      <p>Calendar App</p>
    </div>
  );
}

export default App;

using python manage.py runserver: enter image description here

using npm run inside react app: enter image description here

CodePudding user response:

For any change you make to the project you initialized with create-react-app, running npm start to start your project will handle hot-reloading for you.

This is no longer so when you run your code using Django. Django will serve the site as is so any changes you make after will not be automatically reloaded.

Running with Django will then look like this:

  • Make changes to your code
  • Recompile your code (you can do so with npm run build)
  • Restart your Django server (you can do so with python manage.py runserver)

The assumption is that you have successfully integrated your static files (written with ReactJS) into Django.

  • Related