简体   繁体   English

如何使用不同的目录结构将 django/react 应用程序部署到 heroku

[英]how to deploy django/react app to heroku with different directory structure

I have a django/react app I created using this tutorial here我有一个使用本教程在这里创建的 django/react 应用程序

Although slightly different, I then tried to deploy my app to heroku using this tutorial here虽然略有不同,我则尝试使用本教程中我的应用程序部署到Heroku的位置

The directory structure following the tutorials are different though.但是,教程后面​​的目录结构是不同的。 My directory structure is as follows...我的目录结构如下...

django-todo-react/
  backend/
    backend/
    todo/
    manage.py
    ...
  frontend/
    all my react stuff...

in my django-todo-react folder (the project root directory) I have requirements.txt , Procfile , package.json , and '.gitignore` file.在我的 django-todo-react 文件夹(项目根目录)中,我有requirements.txtProcfilepackage.json和 '.gitignore` 文件。

To my understanding the Procfile should contain something like web: gunicorn backend.wsgi but because my Procfile is in the root directory I do instead the following web: gunicorn backend/backend.wsgi that looks very weird but basically I go into my backend folder where I have my actual backend project I started with django-admin startproject backend and get wsgi .据我了解, Procfile应该包含类似web: gunicorn backend.wsgi但是因为我的Procfile位于根目录中,所以我使用以下web: gunicorn backend/backend.wsgi看起来很奇怪,但基本上我进入了我的后端文件夹我有我的实际后端项目,我从django-admin startproject backend并获得wsgi

I added all the other stuff from the second tutorial I mentioned this one but still no such luck.我添加了所有其他的东西从我提到的第二个教程这一个,但仍然没有这样的运气。 I get a COLLECT_STATIC error and if I silence the error everything passes but I then get a application error when opening my heroku app.我收到一个COLLECT_STATIC错误,如果我将错误静音,一切都会过去,但是在打开我的 heroku 应用application error时我会收到一个application error

I have already tried deploying an app just using the 2nd tutorial and all worked fine but that had the directory structure of the second tutorial.我已经尝试仅使用第二个教程部署应用程序,一切正常,但具有第二个教程的目录结构。 I thought that changing my Procfile to have web: gunicorn backend/backend.wsgi would point to the right thing.我认为将我的Procfile更改为具有web: gunicorn backend/backend.wsgi会指向正确的事情。

So I basically just want to have a server folder which in my case is my backend folder and a client folder which for me it's frontend.所以我基本上只想有一个服务器文件夹,在我的情况下是我的后端文件夹和一个客户端文件夹,对我来说它是前端。 This is not working for me though.但这对我不起作用。

Gunicorn 需要类似 Python 的路径,因此在您的情况下,使用web: gunicorn django-todo-react.backend.backend.wsgi in Procfile应该可以工作。

So I've been trying to figure out the solution to my problem and see that after carefully reading the console for any errors that collectstatic is not finding my static folder.所以我一直试图找出我的问题的解决方案,并在仔细阅读控制台后发现collectstatic没有找到我的static文件夹的任何错误。 It looks for my static folder from within the Django project then a frontend folder, a build folder, and lastly a static.它从 Django 项目中查找我的静态文件夹,然后是前端文件夹、构建文件夹,最后是静态文件夹。

My Django project does not have a frontend folder so instead of creating my react app in the root of my directory I create it in my Django project and make sure to run yarn build so that my frontend folder contains the build/static我的 Django 项目没有前端文件夹,所以不是在我的目录的根目录中创建我的 react 应用程序,而是在我的 Django 项目中创建它并确保运行 yarn build 以便我的前端文件夹包含 build/static

This works fine so if anyone is having an issue with a similar thing I hope this helps.这很好用,所以如果有人遇到类似问题,我希望这会有所帮助。 Also, my question still stands on how to get it working with having two separate directories one for my backend and one for my frontend.此外,我的问题仍然是如何让它与两个单独的目录一起工作,一个用于我的后端,一个用于我的前端。 I am pretty sure it has to do with the STATIC_DIRS but that is just a guess我很确定它与STATIC_DIRS但这只是一个猜测

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM