在Google应用引擎服务之间进行沟通 [英] Communicating between google app engine services
问题描述
我的项目结构如下所示,
My project structure looks like below,
.
├── app
│ ├── api
│ ├── models
│ ├── services
│ │ └── lib
| | |__ worker.yaml
| | |__ worker.py
| |_ main.py
|_ app.yaml
我试图导入 model
来自 app
模块(即默认模块)中的
I'm trying to import models
from app
module (ie, default module) in worker.py
like,
from app.models import db
但它显示没有名为app.models的模块
。但是我可以在 main.py
中实现同样的功能。注意我正在运行 app.yaml
和 worker.yaml
文件。
But it shows No module named app.models
. But I can achieve the same inside main.py
.Note that I'm running both app.yaml
and worker.yaml
files.
推荐答案
部署时,GAE服务/模块不会在模块目录外共享任何 .yaml
文件存在的目录。
When deployed, GAE Services/modules do not share anything outside their module directory, which is the directory in which their .yaml
file exists.
所以 worker.py
不会在
服务
dir(其中 worker.yaml
存在)无法看到 models
。但是 main.py
可以,因为模型在它的 app
dir中(其中 app.yaml exists)。
So worker.py
won't see anything above the services
dir (where worker.yaml
exists), thus it can't see models
. But main.py
can, since models is inside its app
dir (where app.yaml
exists).
您可以在服务中符号链接
如果需要,请参阅在App Engine模块之间共享实体 模型
或者,也许看看关于如何构建多模块应用程序的示例?
Or maybe take a look at Can a default service/module in a Google App Engine app be a sibling of a non-default one in terms of folder structure? for an example of how I'd structure a multi-module app?
这篇关于在Google应用引擎服务之间进行沟通的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!