I am learning how to integrate react with Django.. I found the tutorial by Dennis Ivy useful.. (linked below).
So according to that video, where we create a Django project, and create a separate folder with npx create-react-app appname, we need to npm run build every time we make a change to the react.. Is there a better way to do it?
my settings.py:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [BASE_DIR / 'reactapp/build'],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
STATIC_URL = '/static/'
STATICFILES_DIRS = [
BASE_DIR / 'reactapp/build/static'
]
https://www.youtube.com/watch?v=F9o4GSkSo40&list=PLw4CVL8B1qWH_FsGE53Do_dSN-UdgGiGD&index=21
Since
create-react-appis used,npm run startis a command you can use to host thereactpart of the application. This will start a server and host your application onlocalhost:3000.In general you can check the
scriptssection of thepackage.jsonfile for javascript packages, most application have their commands in this section, to run them on the cli and to run them you'd need to runnpm run <script name>