36
loading...
This website collects cookies to deliver better user experience
mkdir React-Django
cd React-Django
For mac/unix users: python3 -m venv env
For windows users: py -m venv env
For mac/unix users: source env/bin/activate
For windows users: .\env\Scripts\activate
deactivate
pip install django
django-admin startproject project1
cd project1
python manage.py migrate
python manage.py runserver
project1
that contains the manage.py
file:npx create-react-app frontend
cd frontend
npm start
http://localhost:3000
npm run build
cd ..
import os
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'frontend', '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',
],
},
},
]
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'frontend', 'build', 'static')]
python manage.py startapp core
def front(request):
context = { }
return render(request, "index.html", context)
urls.py
file in the project1
folder. We import the "front" view function from the core app and we map it to the default URL " ".from django.contrib import admin
from django.urls import path
from core.views import front
urlpatterns = [
path('admin/', admin.site.urls),
path("", front, name="front"),
]
python manage.py runserver