栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

配置:django + react

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

配置:django + react

使用脚手架的连接步骤
  1. react:npx create-react-app reactapp
  2. django:django-admin startproject djangoproject
  3. 把reactapp目录放入djangoproject目录中
  4. reactapp目录下:npm run build
  5. 连接django的 templates 和react的 build/index.html
    1. settings.py 设置template项并在文件末尾加入STATICFILES_DIRS:
      'DIRS': [
              os.path.join(base_DIR, "reactapp/build"),
          ],
      
      STATICFILES_DIRS = [
          os.path.join(base_DIR, "reactapp/build/static"),
      ]
      
    2. 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')),   ##新加的
      ]
      
配置成功

python manage.py runserver:

前后端分离工作
  • react部分:代码更新之后需要重新npm run build
  • django部分(MVT)
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/444888.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号