项目结构 - 链接 models.py

Project structure - linking models.py

构建表单以将数据从 AppEngine(Python) 提交到 Google 数据存储。

我想将我的 ndb 模型从 main.py 移到它们自己的文件 models.py 中。这两个文件都位于项目的根目录中。

现在,当我使用 AppEngine(local) 测试我的表单时,我的模型对象没有被创建。

基本上我如何 link models.py 到 main.py 以便我的处理程序可以从模型创建对象?

我的对象叫做 Consults,来自 models.py 的模型是:

consult = Consults( consult_date=booking_date,
                    consult_time=booking_time,
                    ...)

当我提交表单时 AppEngine 的错误是:

NameError: global name 'Consults' is not defined

为您需要的模型添加到 main.py 导入:

from models import Consults

consult = Consults( consult_date=booking_date,
                    consult_time=booking_time,
                    ...)