- react:npx create-react-app reactapp
- django:django-admin startproject djangoproject
- 把reactapp目录放入djangoproject目录中
- reactapp目录下:npm run build
- 连接django的 templates 和react的 build/index.html
- settings.py 设置template项并在文件末尾加入STATICFILES_DIRS:
'DIRS': [ os.path.join(base_DIR, "reactapp/build"), ],STATICFILES_DIRS = [ os.path.join(base_DIR, "reactapp/build/static"), ] - urls.py
from django.contrib import admin from django.urls import path from django.views.generic import TemplateView ## urlpatterns = [ path('admin/', admin.site.urls), path('', TemplateView.as_view(template_name='index.html')), ##新加的 ]
- settings.py 设置template项并在文件末尾加入STATICFILES_DIRS:
python manage.py runserver:
- react部分:代码更新之后需要重新npm run build
- django部分(MVT)



