gpt4 book ai didi

Django + react : How to connect them for deployment?

转载 作者:行者123 更新时间:2023-12-04 10:24:03 24 4
gpt4 key购买 nike

我正在使用 Django+DRFCELERY+REDISReactJs+REDUXJWT 运行应用,我很难将 backendfrontend 连接起来进行部署。

我已经使用 create-react-app 生成 React 代码;和 npm run build 生成生产版本。

我一直在四处寻找,但找不到有关如何将它们链接在一起的教程。

如果你们有任何我可以关注的链接,我将不胜感激。

最佳答案

您不需要将 React 文件“移入”Django。只需分别为他们服务。

这就是我为我的项目服务的方式:

enter image description here

我从 /api/ url 提供我的 API,所以这是我的 Nginx 配置的粗略表示:

server {

# urls that start with /api or /admin
location ~ ^/(api|admin) {
# pass them to uwsgi or gunicorn
...
}

# urls that start with /media
location /media {
# serve from your project's media folder
...
}

# urls that start with /static/admin
location /static/admin {
# these requests are made to admin's static files
# serve them from your staticroot folder
# i.e. where your files are stored after you run `collectstatic`
...
}

# everything else
location / {
# serve from frontend build folder
root /path/to/the/build/folder;
index index.html;
# this is important
# first try to find files matching url, like css, or js, or favicon
# if nothing found, serve the index.html
try_files $uri /index.html;
}
}

关于Django + react : How to connect them for deployment?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60705957/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com