【问题标题】:Project structure - linking models.py项目结构——链接models.py
【发布时间】:2017-02-20 14:29:21
【问题描述】:

构建一个表单以从 AppEngine(Python) 向 Google Datastore 提交数据。

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

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

基本上我如何将 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

【问题讨论】:

标签: python google-app-engine app-engine-ndb


【解决方案1】:

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

from models import Consults

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

【讨论】:

  • 感谢@DanCornilescu,简单但很有帮助;)
猜你喜欢
  • 2011-02-06
  • 1970-01-01
  • 2013-12-15
  • 1970-01-01
  • 1970-01-01
  • 2022-10-24
  • 1970-01-01
  • 1970-01-01
  • 2011-01-16
相关资源
最近更新 更多