简体   繁体   English

如何在单个 DigitalOcean 应用程序上安装 React 和 Python 包?

[英]How can I install React and Python packages on a single DigitalOcean App?

I have a Django project with a ReactJS application (index.html) directly integrated into the Django template system.我有一个 Django 项目,其中 ReactJS 应用程序 (index.html) 直接集成到 Django 模板系统中。 This is an alternative way of integrating Django and React where you can have shared authentication and have your React app seamlessly display within the template (look and feel) of the Django website.这是集成 Django 和 React 的另一种方式,您可以在其中共享身份验证并让您的 React 应用程序无缝显示在 Django 网站的模板(外观)中。

One issue you must overcome is getting your DigitalOcean environment built so that it includes all the packages and dependencies for Python, Django, and NodeJS/React.您必须克服的一个问题是构建 DigitalOcean 环境,使其包含 Python、Django 和 NodeJS/React 的所有包和依赖项。 The DigitalOcean platform does not include any specific instructions on accomplishing this complete setup. DigitalOcean 平台不包含任何关于完成此完整设置的具体说明。 I've struggled to find answers here too.我也一直在努力寻找答案。

If you are not using Docker, DigitalOcean will have access to your code and thus it can determine what languages your site uses.如果您不使用 Docker,DigitalOcean 将有权访问您的代码,因此它可以确定您的网站使用的语言。 If it determines you are using Python, it will load buildpacks specifically for reading your requirements.txt or Pipfile and installing all the packages listed within them.如果它确定您使用的是 Python,它将专门加载构建包以读取您的 requirements.txt 或 Pipfile 并安装其中列出的所有包。

If you add ReactJS as mentioned above, your project will now have dependencies that are managed and installed outside of the requirements.txt or Pipfile.如果您如上所述添加 ReactJS,您的项目现在将具有在 requirements.txt 或 Pipfile 之外管理和安装的依赖项。 Thus, DigitalOcean will not know of those dependencies and they will not load into your environment.因此,DigitalOcean 不会知道这些依赖项,它们也不会加载到您的环境中。

You cannot simply add the dependencies into your requirements.txt or Pipfile, since they are not intended for Python. You must instead, leave them in the package.json file, which is built out in your local environment when you use NPM to install those packages required for NodeJS and React.您不能简单地将依赖项添加到您的 requirements.txt 或 Pipfile 中,因为它们不适用于 Python。您必须将它们保留在 package.json 文件中,当您使用 NPM 安装所需的那些包时,该文件是在您的本地环境中构建的对于 NodeJS 和 React。

DigitalOcean now only requires that you include the packages.json file when publishing to DigitalOcean. DigitalOcean 现在只要求您在发布到 DigitalOcean 时包含 packages.json 文件。 if you are deploying from a Github repo, you can simply add the packages.json file and commit it.如果您从 Github 存储库进行部署,您只需添加 packages.json 文件并提交即可。 When your repo is pushed to DigitalOcean with the packages.json file, DigitalOcean will detect the additional packages for NodeJS and React.当您的 repo 使用 packages.json 文件推送到 DigitalOcean 时,DigitalOcean 将检测 NodeJS 和 React 的附加包。 When it detects them it associates it with a buildpack specific for NodeJS and it will install those packages.当它检测到它们时,它会将它与特定于 NodeJS 的构建包相关联,并将安装这些包。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当我在 nodeJS 中将代码作为 python shell 运行时,如何永久安装 python 包? - How can I install python packages permanently when I am running my code as a python shell in nodeJS? 如何安装React-Native NPM软件包? - how to install React-Native NPM packages? 如何解决此问题 npm 错误以安装我的反应应用程序? - how can I fix this problem npm error to install my react app? 如何使用纱线安装Bower包? - How do I install Bower packages with Yarn? npm peerDependencies React:无法安装任何软件包 - npm peerDependencies React : can't install any packages 如何在本地安装Meteor Atmosphere软件包,以便对其进行修改? - How do I install Meteor Atmosphere packages locally so I can make modifications to it? 当我遇到网络请求失败错误时,如何安装 npm 包? - How can I install npm packages when I have a failed network request error? Azure 应用服务中的节点应用 npm install 超时,即使对于单个包,无论如何,非常不可靠 - Node app in Azure App Service npm install timeout even for single packages no matter what, extremely unreliable 如何将程序包原生Node.js安装到node_modules中? - How can I install packages native Node.js into node_modules? 如何通过@types为scoped / namespaced包安装TypeScript声明? - How can I install TypeScript declarations for scoped/namespaced packages via @types?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM