django-create-react-app
----------------------
This app helps us to integrate the react in django project through create react app template. This app works both in dev and production mode of the react.
### Why django-create-react-app
* works with the asset-manifest plugin on the frontend which is used/maintained by create react app
* No Frontend code modification needed for SPA
* Dev Mode works with frontend server through http (localhost:3000)
Quick start
-----------
### Install
```
pip install django-create-react-app
```
Add "create_react_app" to your INSTALLED_APPS setting like this::
```
INSTALLED_APPS = [
...
'create_react_app',
]
```
---
# Settings Configuration
### Add Build Directory in the Settings
```
yarn build or npm run build
```
This command creates the build directory inside the react app folder.
```
REACT_BUILD_DIRECTORY = os.path.join(BASE_DIR, 'app', 'react', 'build')
This is the path in which build is created
```
### Add Below code for Collectstatic Finder to find the build folder ::
```
Build Directory created django needs to treat it static directory
STATICFILES_DIRS = (
os.path.join(REACT_BUILD_DIRECTORY, 'static'),
)
```
### Add create react app configuration into your settings::
```
CREATE_REACT_APP = {
'DEFAULT': {
'BUNDLE_DIR_NAME': REACT_BUILD_DIRECTORY,
'FRONT_END_SERVER': "http://localhost:3000/",
'IS_DEV': False,
}
}
```
### Use it in your templates ::
```
{% load react_bundle_loader %}
<html>
<head>
{% render_bundle_css %}
</head>
<body>
....
{% render_bundle_js %}
</body>
</head>
```
#Adding Multiple React Apps inside django Project
```
CREATE_REACT_APP = {
'DEFAULT': {
'BUNDLE_DIR_NAME': REACT_BUILD,
'FRONT_END_SERVER': "http://localhost:3000/",
'IS_DEV': False,
"PUBLIC_PATH_DEV": "http://localhost:3000/",
"PUBLIC_PATH": "/static/"
}
'ADMIN': {
'BUNDLE_DIR_NAME': REACT_BUILD,
'FRONT_END_SERVER': "http://localhost:3000/",
'IS_DEV': False,
},
}
```
#### is_dev: True
make sure react app is running on FRONT_END_SERVER on same port which is declared
#### is_dev: False
make sure build path is pointed to the right build directory
### Rendering react admin app inside templates ::
```
{% load react_bundle_loader %}
<html>
<head>
{% render_bundle_css "ADMIN" %}
</head>
<body>
<div id="root"></div>
{% render_bundle_js "ADMIN" %}
</body>
</head>
```
### Using Preloading ::
The is_preload=True option in the render_bundle_css or render_bundle_js template tag can be used to add rel="preload" link tags.
```
{% render_bundle_css is_preload=True %}
```
### Add attributes
add some extra attributes to the tag
```
{% render_bundle_js attrib="async" %}
{% render_bundle_js attrib="disabled" %}
```
### migration from 0.8.4 to 0.9
"is_dev" changed to "IS_DEV"
is_dev in lowercase will not work
### docker support
PUBLIC_PATH_DEV default value will be FRONT_END_SERVER, which will be used for incase of docker
PUBLIC_PATH_DEV will be used in case of docker to http://localhost:3000/
FRONT_END_SERVER: host.docker.internal
### django storage support
change PUBLIC_PATH to storagepath e.g
PUBLIC_PATH:"https://234234234.aws.com/static/"
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
资源分类:Python库 所属语言:Python 资源全名:django-create-react-app-0.9.0.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源推荐
资源详情
资源评论






格式:zip 资源大小:775.5KB

























收起资源包目录




























共 23 条
- 1
资源评论


挣扎的蓝藻
- 粉丝: 15w+
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- 高中信息技术会考网络技术应用试题.doc
- 企业财务管理信息化建设的措施.docx
- stratovirt-Rust资源
- vb点菜系统课程设计报告书.doc
- 基于移动互联网环境下的大学英语混合式教学模式探究.docx
- 人工智能及其商用前景.docx
- 计算机电子工程技术的有效运用与发展.docx
- 互联网计算机网络职业生涯规划.docx
- 多媒体技术在技工院校计算机教学中的问题及其对策.docx
- UMC-移动应用开发资源
- 计算机信息化技术在教育招生考试中的应用分析.docx
- 物联网zigbee无线智能家居解决方案横版.pdf
- 大数据时代下报业经营的转型和创新.docx
- 数字电子钟电路方案设计书08自动化1班张宇铎.doc
- 电气工程及其自动化的发展趋势.docx
- 基于STC8系列的ECBM函数库V3-单片机开发资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制
