使用 Django 在 Heroku 上部署多个项目

发布于 2024-12-23 14:58:48 字数 432 浏览 6 评论 0原文

我想将两个单独的 Django 应用程序部署到 Heroku。两个应用程序具有两个独立的域名,在逻辑上彼此不同。我设置了一个包含所有 Python/Django 内容的 venv。现在,我可以创建另一个应用程序来复制另一个项目中的所有 Python/Django 内容。但是,有没有办法使用相同的 venv?

我的文件结构目前看起来像这样

django
-.git
-projectname_1
-venv
.gitignore
requirements.txt

当我尝试在 django 下添加 projectname_2 时,我收到一条错误消息 Django app must be in a package subdirectory

有没有正确的方法来添加第二个应用程序使用相同的 venv?

I would like to deploy two separate Django applications to Heroku. Two applications, with two separate domain names, that are logically different from each other. I set up a venv that contain all the Python/Django stuff. Now, I could create another application that duplicates all the Python/Django stuff in another project. But, is there a way to use the same venv?

My file structure currently looks like this

django
-.git
-projectname_1
-venv
.gitignore
requirements.txt

When I tried to add projectname_2 under django I got an error saying Django app must be in a package subdirectory

Is there a correct way to add a second application using the same venv?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

习ぎ惯性依靠 2024-12-30 14:58:48

当您的项目不符合 Heroku 的 Django 项目规范时,就会出现此错误。

具体来说,当 Heroku 在 ~/your_app_name/settings.py 中找不到设置文件并因此假设它是非 Django Python 应用程序时,就会发生该特定错误。但随后它确实在项目根目录(~/)找到了settings.py 和manage.py。

抛出这个错误的具体Heroku源码是:
https://github.com/heroku/heroku-buildpack-python /blob/master/bin/compile

你的目录应该看起来像这样:

~/.gitignore
~/Procfile
~/requirements.txt
~/your_app_name/
~/your_app_name/manage.py
~/your_app_name/settings.py
~/your_app_name/etc...

你最好的选择是使用两个单独的 Heroku 应用程序。 Heroku 对您正在部署的应用程序类型做出一些假设,但不一定考虑多个应用程序。

另外,最好不要检查您的 virtualenv。只需确保所有依赖项都在requirements.txt 中定义,Heroku 就会自动将它们安装在新的 virtualenv 中。

This error occurs when your project doesn't conform to Heroku's specs for a Django project.

Specifically, that particular error occurs when Heroku did not find a settings file at ~/your_app_name/settings.py and therefore assumed it's a non-Django Python app. But then it did find settings.py and manage.py at your project root (~/).

The specific Heroku source code that throws this error is:
https://github.com/heroku/heroku-buildpack-python/blob/master/bin/compile

Your directory should look something like this:

~/.gitignore
~/Procfile
~/requirements.txt
~/your_app_name/
~/your_app_name/manage.py
~/your_app_name/settings.py
~/your_app_name/etc...

Your best bet really is to use two separate Heroku apps. Heroku makes some assumptions about what type of app you are deploying and doesn't necessarily account for multiple apps.

Also, it's probably best to not check in your virtualenv. Just make sure all your dependencies are defined in requirements.txt and Heroku will install them automatically inside a new virtualenv.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文